|
百度站长平台链接自动提交-js代码- <script>: R4 ]) J8 M( |' ?0 D3 [- Y$ c' f
- (function(){
; n, j% I7 d Y+ Q+ j - var canonicalURL, curProtocol;1 R, o* _5 t% a0 T4 f+ q
- //Get the <link> tag
7 h; k3 ^( P2 Y5 `8 U2 N: d. V - var x=document.getElementsByTagName("link");
" z$ Y8 ?$ k' u4 T* i9 ] - //Find the last canonical URL
1 b4 _% e! U* u% p/ }* j - if(x.length > 0){- q7 k% J1 w: G% P% J( g3 ^
- for (i=0;i<x.length;i++){, I$ e: O. g" x; A( W: u0 a0 U' O
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
2 @! a- T0 R, p9 Y - canonicalURL=x[i].href;9 I$ T* V) q: x6 s0 U0 i
- }
; m/ I) n% u* O. K - }* V4 ~, Q4 Y, w" M6 X2 J
- }. {5 M0 n+ ]2 e0 A3 y; }: o( f" c$ E
- //Get protocol
5 ^7 j, r4 L6 ~! q3 m - if (!canonicalURL){( F! N ?# L5 v0 O2 J7 ?" B. I3 K
- curProtocol = window.location.protocol.split(':')[0];
$ R0 m, ?8 ~6 S' o6 l - }/ P: d! R6 l3 p+ H9 M( ~ ]
- else{
# G0 a) O% H* |$ g; P - curProtocol = canonicalURL.split(':')[0];
6 ?" b9 ?( s: f( Q- P+ \2 m - }' J7 |8 p* P* Q- i- J" _
- //Get current URL if the canonical URL does not exist
5 v) `' J/ p0 \8 O1 ^& } - if (!canonicalURL) canonicalURL = window.location.href;
" }; ?/ p' b* q8 ^4 H( _, @8 m - //Assign script content. Replace current URL with the canonical URL5 F$ h3 ^& U/ B! I- [* g
- !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);})();
5 v! m$ F* v$ B: _1 q! h - </script>) G: I* B. i6 o' @) Z
复制代码
: j) \+ k' ]3 K5 \$ ~7 Z9 r' h- P) T9 ~% z
8 A% p' L& w3 o9 w
|
|