|
|
百度站长平台链接自动提交-js代码- <script>) C$ f v- c7 _8 J
- (function(){. a; w3 @& J3 A2 f* I$ b& L) y& A$ f
- var canonicalURL, curProtocol;
! |: V& ?/ c$ p - //Get the <link> tag
0 v# }9 }" ], n - var x=document.getElementsByTagName("link");
7 k O0 z- Z) q. Y5 L- t - //Find the last canonical URL
3 F/ a0 W) ~7 I# v2 J' Y' U4 w - if(x.length > 0){
% M$ q9 T: Q5 K2 P0 ~! T) [ - for (i=0;i<x.length;i++){
" O* R! F7 e! h: o6 r - if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){ y8 S- s& }6 B1 |9 Y6 Y) e( ~( [
- canonicalURL=x[i].href; H2 t$ T, i3 o0 f3 ?$ Z
- }
) j ?' w2 k: g1 j1 K0 b$ j - }& ^% }8 D# X' M6 Y' h% F
- } K# f |& P" i- l. j1 h# ?( b3 p
- //Get protocol
) _( H1 u0 A# d3 H& q b3 | - if (!canonicalURL){
8 d. L9 n7 \6 [: v w0 S - curProtocol = window.location.protocol.split(':')[0];
' ~' ^% O1 A. k. d - }, X# s- s' C2 `/ G$ I, I5 W. B
- else{
) l. G |( V$ ~* r N) S - curProtocol = canonicalURL.split(':')[0];/ N- \# e* Q, R r/ S8 c
- }
9 v2 Q% e z3 g! t - //Get current URL if the canonical URL does not exist; |. T& R8 |- H2 o: e/ r
- if (!canonicalURL) canonicalURL = window.location.href;
: \4 w5 u) M5 p2 @ - //Assign script content. Replace current URL with the canonical URL
0 G& n/ s% H9 d3 O8 D - !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);})();- D4 _9 W5 |; s' {
- </script>
) u, R8 v5 f6 x- _6 f c
复制代码 & B& M- p, I- D
7 I0 K4 E* P5 E) C/ C5 k: _- U; b: X3 A
|
|