|
|
百度站长平台链接自动提交-js代码- <script>6 C0 \7 b' E8 ] y
- (function(){, L& Z) r o/ P" U0 F8 a
- var canonicalURL, curProtocol;
& Y% Q6 B1 Z% Q0 B# ]+ ^" o - //Get the <link> tag( f' B8 C" W9 Q9 S
- var x=document.getElementsByTagName("link");
- J0 c( t- v7 V) y7 c, \6 z - //Find the last canonical URL
, m6 c3 a- s" b( l3 i - if(x.length > 0){
4 P1 S; I Q. L i4 C: O i" f' } - for (i=0;i<x.length;i++){. l; b) v* V. G
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){# T0 |$ ?' b; E) A2 j* D6 Y; _6 U8 q
- canonicalURL=x[i].href;5 S+ q# F: w$ D# ]8 L
- }
3 q/ w) F; E4 m# M6 [" Y - }' l( ?5 m: n+ I K, P5 j
- }* [2 j- F: L u
- //Get protocol
3 }( l$ U. y: |$ k- v4 t5 b - if (!canonicalURL){
" o: F. h, F9 K4 m* U Q' n3 ]9 H - curProtocol = window.location.protocol.split(':')[0];
3 M6 C p4 | x+ N0 G - } R; Y; Z. b- E$ x9 c3 Q1 ]: u
- else{3 x' }# k2 K' w: a1 w% S
- curProtocol = canonicalURL.split(':')[0];
# x1 |& s4 N) a" {6 M! q. d - }
! e! t4 e, F# m: H - //Get current URL if the canonical URL does not exist
/ w {1 l' ?: _( f4 k8 r - if (!canonicalURL) canonicalURL = window.location.href;
4 [5 \# B; r. [1 K' p+ U* m - //Assign script content. Replace current URL with the canonical URL
% S; C4 ] t7 r; F- D: E - !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);})();
7 J K: S. x* f9 r2 H$ e1 m - </script>
7 x6 O. q T0 K, }0 |0 }) m
复制代码
p/ M0 n6 P. d" |4 x! h6 F# E. ^# @/ f! J O, v
3 L/ W: C' M n4 l: R* T3 U
|
|