|
百度站长平台链接自动提交-js代码- <script>
/ ^8 e$ J6 h$ O2 u9 E - (function(){+ |5 A: F' N' _& k0 F
- var canonicalURL, curProtocol;& n; c7 E+ T. D
- //Get the <link> tag
+ G( `7 \+ n0 e/ R, ^. B- H - var x=document.getElementsByTagName("link");* m( P8 @9 Q2 U" F
- //Find the last canonical URL
7 g" ^3 z, l+ @* M( a+ C4 W0 N% s - if(x.length > 0){
5 L3 b* P# I: X! ~' Y - for (i=0;i<x.length;i++){* _" |( N7 z9 j Z4 C1 Y+ U2 \
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){& W4 w4 |6 ~) e j8 h" G$ k
- canonicalURL=x[i].href;) a9 }" F+ m4 |# t& N5 G% ]- E
- }; I8 W/ A7 f& f' Q: h! n
- }
# S. t. k! o2 e e - }
$ a" j ?% X& S' a$ }0 H! a" s1 s4 B - //Get protocol/ I+ s' ~) o$ J- X" {0 @, }( d
- if (!canonicalURL){
+ k: Q+ ^ r$ g' s( ^7 j - curProtocol = window.location.protocol.split(':')[0];+ V' b2 e F, r5 a P3 M* S
- }/ o& P2 D8 t' b3 a* i1 H
- else{: v& O/ M7 i% }. d. a- o
- curProtocol = canonicalURL.split(':')[0];, ?( }9 n# d9 F) q3 f2 k& ` G
- }: n2 S! x* H5 _6 w
- //Get current URL if the canonical URL does not exist
" n" `- P1 V# ~, V( @2 c& G - if (!canonicalURL) canonicalURL = window.location.href;: p# r- t2 \9 v) e5 _$ \. k
- //Assign script content. Replace current URL with the canonical URL
7 A* m! { q5 w K2 m - !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);})();
0 D( g8 ?2 N3 g1 Y; ^- J4 N - </script>
, B7 Y# i! Q2 e! c4 \/ Y; J7 ?
复制代码
4 ^& v% h+ E+ k. I) e$ }8 b1 ^& I: m) V( _) d$ O/ M8 R6 N7 c
$ X1 j$ o; b3 B7 C) ^ |
|