|
|
百度站长平台链接自动提交-js代码- <script>- B: k) i5 a; _! K9 T% Y' Y! S
- (function(){' J* J- C I! `+ ~
- var canonicalURL, curProtocol;2 m) A f* l6 ]! m4 k4 @
- //Get the <link> tag. }0 m2 t7 M7 c1 S& Y; r
- var x=document.getElementsByTagName("link");, d; n! L: V1 k0 ]% b! O
- //Find the last canonical URL6 Z8 N: ^! g. V6 F! s
- if(x.length > 0){
/ R; c% i8 k5 p! A - for (i=0;i<x.length;i++){
9 |1 x, `# j" B- { - if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){8 e A# _, z- t# Q2 G$ f9 ` Z
- canonicalURL=x[i].href;
$ O' \) Q6 d' E- d - }$ I- B( \0 @/ q1 |3 _
- }, y( b I$ m% [+ v
- }
' z" O' B% p, K7 Y& { - //Get protocol
5 B) M- B7 ?$ C - if (!canonicalURL){
4 Q3 [, ]8 o) v' O% F, X0 s - curProtocol = window.location.protocol.split(':')[0];
+ F/ F- M) C F5 ] - }
: S4 n% L1 t6 p0 D" {( @1 R& j - else{
2 m/ Q3 K+ p( ]8 _. ~5 b; l8 x - curProtocol = canonicalURL.split(':')[0];
: G# U4 M) u7 |! a - }1 h- f @1 W* s
- //Get current URL if the canonical URL does not exist x8 C5 ^ N* E
- if (!canonicalURL) canonicalURL = window.location.href;
, q6 D* X% y, Z. ` - //Assign script content. Replace current URL with the canonical URL
& n* [3 T& ^% l! D- ?0 k) w - !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);})();$ ^8 q% W6 e; E$ q7 b
- </script>
0 B( C( Y1 E) D, t) y! n
复制代码
5 x5 z1 A; T# Y$ J) u% c h" f5 c& h
9 N+ f; B# t6 c" ]9 m
|
|