|
|
百度站长平台链接自动提交-js代码- <script>) }* v' l! ?- v1 g
- (function(){
) z' _5 H! h- t: ` - var canonicalURL, curProtocol;. h" M# x* Y) J+ a" Q8 y
- //Get the <link> tag
0 z" d$ V$ F- v9 O. ?# `, t - var x=document.getElementsByTagName("link");* a; k4 o" _" \5 J
- //Find the last canonical URL
6 P& D% F1 T* Y9 ?" v - if(x.length > 0){* }. k7 r9 B% C2 j) ^5 `
- for (i=0;i<x.length;i++){, ]" E! ~; S8 y* |3 G
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
8 R$ n* @* V, r" j5 c* Y7 G( S7 m2 ? - canonicalURL=x[i].href;( ~4 g' k$ z( a# L5 P |& x' D
- }
5 g7 `5 Z8 T9 M8 c: ? - } U2 Z* r/ T: N- g/ ^2 c7 ^& ~
- }7 G* R2 A/ n( s! K; H+ S
- //Get protocol
/ a, f6 _( v0 p; e M - if (!canonicalURL){
+ V" B \; v( W1 T2 _, v - curProtocol = window.location.protocol.split(':')[0];
* D& p" m& W' U* ]; @2 i J - }
6 M/ }2 f3 M( ? - else{: c/ _+ d+ ]7 i" z Q1 R
- curProtocol = canonicalURL.split(':')[0];
' z$ J2 f) C+ G* t5 J! r$ {) z - }6 Y( k: [8 S+ y% G8 _
- //Get current URL if the canonical URL does not exist
3 L$ B3 U' J5 A; ~+ c; z0 i - if (!canonicalURL) canonicalURL = window.location.href;
( a: H1 O2 L8 ^/ G. r. k - //Assign script content. Replace current URL with the canonical URL
4 z; C. x% g2 M [$ L, y" s/ n - !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);})();
3 G# Z3 f) q) `+ ~7 Q! q - </script>! ?# U, u" o* N2 P6 X% h) Z! S& a
复制代码 . n* H& p$ @# P6 A6 I! y3 c
; D' B( i/ v- m
# j! ]) j- w3 J) U" x+ M/ ` |
|