|
|
百度站长平台链接自动提交-js代码- <script>2 j8 n( W N, r# ]# T- s
- (function(){- E8 g+ S* N/ t5 N2 D1 b: i
- var canonicalURL, curProtocol;
6 Y$ e; B# K O1 A - //Get the <link> tag
$ t3 C8 t5 Q" {9 O a - var x=document.getElementsByTagName("link");
% w8 \& c) A5 N: } - //Find the last canonical URL0 A8 w+ _# p" U3 b% s( h( p+ M
- if(x.length > 0){/ Q9 m" T2 _3 x) I4 [! R; O; l
- for (i=0;i<x.length;i++){
7 ~+ T/ W# ?( }2 W6 ]5 L* w5 A+ h+ ~ - if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){& |( L" A5 _) v
- canonicalURL=x[i].href;
: `/ }/ Z T5 y$ @$ c - }
+ b. {8 }. {/ `1 Z - }) z3 G( M5 a2 x- i% ?( o+ k
- }) Q! Z9 D! R( h
- //Get protocol+ D$ o2 `. O9 s' V5 t7 q% r
- if (!canonicalURL){3 O6 c7 {: w: g% O; H. z
- curProtocol = window.location.protocol.split(':')[0];1 I& x& ^0 y/ L4 s8 Z
- }
) @. M' ?$ Q8 p5 e" C0 C - else{
5 M5 d* {/ Z7 s* \ G* x, _' R - curProtocol = canonicalURL.split(':')[0];
0 B4 X7 M. _+ }% O9 l. a - }! o$ U: R, G* \/ q; [* j" {
- //Get current URL if the canonical URL does not exist$ K; l2 w0 @$ y( h. [5 ~; e
- if (!canonicalURL) canonicalURL = window.location.href;* _; F9 J1 y t. q7 {
- //Assign script content. Replace current URL with the canonical URL
6 d/ P& Q. _+ J, s - !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();6 M- h/ N0 B4 g& |
- </script>
1 c/ f7 R5 F. }, |, E1 U1 [, O, ^
复制代码
$ v2 W+ r' U( n0 |
4 X/ v" s8 e! ?& @9 P- ~$ P3 r
+ K) q* D. f6 `! _: \, o- ^* M$ p, _ |
|