|
百度站长平台链接自动提交-js代码- <script>- ` ?) \" f* \( s
- (function(){
2 U1 g* p$ [( `- f- i" b1 k - var canonicalURL, curProtocol;4 I* X9 ~% y2 J
- //Get the <link> tag& i. V5 k( U& r+ t
- var x=document.getElementsByTagName("link");1 R- o: z) u% {' U! f1 E* f
- //Find the last canonical URL
4 q: f( i$ ]1 J n - if(x.length > 0){
$ k! P7 r* ?. b! ?9 ?. J" E - for (i=0;i<x.length;i++){' t8 f( G) g' o! U& n$ y) r
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){" Z" X; J* |: s
- canonicalURL=x[i].href; _5 D% I# t, a& ?- X1 ^
- }
5 I5 O$ e, c/ A: E6 Q8 n - } q& k8 v$ j7 A$ m8 [! N/ w( x
- }
, b. |# l7 b4 Q% H% ~9 w - //Get protocol! Z$ T7 h1 A3 d( Z U# u
- if (!canonicalURL){
% b) u+ x% Q+ k# L - curProtocol = window.location.protocol.split(':')[0];
; f- W' F; k T. H- e - }+ m+ q3 O3 h* N. U% F0 `
- else{
5 a5 C9 E, G; Q( F1 E" y0 P! \ - curProtocol = canonicalURL.split(':')[0];
( ` b( l8 J* q3 z2 t - }
& k' S2 A5 s( J - //Get current URL if the canonical URL does not exist
- R5 J5 Y2 ]" B* W' Z - if (!canonicalURL) canonicalURL = window.location.href;
* W! o( C/ Z u& r4 L - //Assign script content. Replace current URL with the canonical URL- P+ R: r P4 h" t- f
- !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 x* Y* ? ^% t! } - </script>6 {2 }+ C* T- B; T- M: v
复制代码
' o9 a: x6 z0 ~: Q
9 g. q0 b. e9 h$ K* L% k* _ t. U5 q! Q. y, t5 v1 l
|
|