|
|
百度站长平台链接自动提交-js代码- <script>8 [- f( I. ~$ }3 r% q
- (function(){* M% [; c r ^* p* R
- var canonicalURL, curProtocol;9 Q1 `7 e b. y! |7 @; T4 M
- //Get the <link> tag
% W: T7 x* u- A5 v' U/ L$ G. V- l, { - var x=document.getElementsByTagName("link");
& a! l+ x; h- ]- F, y2 w1 P( m' g - //Find the last canonical URL
3 w+ @2 r0 P3 y! z* j - if(x.length > 0){
n# S# a0 f! T- P$ ]. Q. g - for (i=0;i<x.length;i++){) o2 I' K# c) @6 ~) o
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
3 t. k. J& S) W" E - canonicalURL=x[i].href;4 }3 H6 [; x: Z
- }/ g! N1 ]* W5 e8 I
- }
) C6 J0 B" B3 r1 A( J; y1 ` - }
/ o# M+ H2 N: w8 I$ w3 h; V: s - //Get protocol
0 D( ?& }/ F, q7 m) j - if (!canonicalURL){- W3 q t, a* V$ u. \' i8 X0 n
- curProtocol = window.location.protocol.split(':')[0];4 }, d" w) h. d2 Y: Q
- } H+ \/ K! a: T' i! F
- else{
0 ^- C8 D6 G$ R w& k1 W; e* q - curProtocol = canonicalURL.split(':')[0];
; ]( h. J ?' X. D1 g4 ~ - }
& X& D8 S& {5 N1 a - //Get current URL if the canonical URL does not exist) c- p e: ?+ I, I/ Z% @) k: s
- if (!canonicalURL) canonicalURL = window.location.href;/ i* ^, A% T& Z3 x# p7 v
- //Assign script content. Replace current URL with the canonical URL4 P& `. K0 N3 V# 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);})();
# R' l& G. X, g; u - </script>$ F4 u, y- O0 E8 Q F
复制代码
! O2 R9 z9 B' c! I' V& ?) D1 c7 B
, f8 `8 \' A+ s1 F4 e' U* x |
|