|
|
百度站长平台链接自动提交-js代码- <script>5 Z- W- Z6 i1 b7 h2 A$ s* m
- (function(){3 ]- B" X2 r! O7 e7 [4 R
- var canonicalURL, curProtocol;) F) @3 T& t9 \/ r: `: B5 M0 R
- //Get the <link> tag
, K& j7 G/ k4 y9 ^* a - var x=document.getElementsByTagName("link");( {8 G7 A8 @# ~9 A8 l$ {& j% f
- //Find the last canonical URL
: Q, r& s: [2 C - if(x.length > 0){9 ^0 ^7 v1 }+ e, W; {! z1 H
- for (i=0;i<x.length;i++){
. d0 ^: U+ j8 a0 X! j - if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){7 g4 H7 [& T4 J& Q
- canonicalURL=x[i].href;
* r- d, z+ S9 |# x! O' g+ L - }3 A$ b* E! B( f5 \9 |$ ]
- }+ W! B& |- q+ A
- }' }: L! V: C# l- s& q( W
- //Get protocol& n# l! ]7 p/ x4 O, B* k7 y4 u. v
- if (!canonicalURL){% A2 G* P% a( }; K- O
- curProtocol = window.location.protocol.split(':')[0];
* U5 B( Z/ n e6 f. z, K- R) k - }. G) Q6 r7 k2 M8 k+ W4 |" v
- else{
( u3 C% k5 I) G5 o - curProtocol = canonicalURL.split(':')[0];) m6 ~& F% r* n8 U8 N1 D: I4 ]
- }
4 \+ X! g* w7 {: q% k/ ? - //Get current URL if the canonical URL does not exist
3 m6 v& y* o; C0 p; X - if (!canonicalURL) canonicalURL = window.location.href;0 H+ L, j5 Y7 F0 o( j1 ^
- //Assign script content. Replace current URL with the canonical URL
7 s, `8 m) I& l6 O" H9 H1 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);})();
7 |. J% C2 x: d- J/ d+ k. r+ K$ N1 j - </script>
6 J) z& E# i4 [7 l
复制代码 ! X! |7 n6 W8 C- V" H5 n9 l
$ k+ b( }2 C% q1 t5 ?" j( ~
7 s* L/ l" \2 c
|
|