|
|
百度站长平台链接自动提交-js代码- <script>
! O" ^" s7 @6 h7 X8 D) l - (function(){
" E1 }/ I2 Y8 \1 F - var canonicalURL, curProtocol;
4 [, B4 K' h5 Z) ~1 U) _ - //Get the <link> tag$ Y) C- j( Z$ u4 [
- var x=document.getElementsByTagName("link");! ~" f( N% ^7 H
- //Find the last canonical URL
( ?0 L: |/ N( @4 e; X - if(x.length > 0){
6 v* J. p2 ~" Q* ]8 S% Z, g' w - for (i=0;i<x.length;i++){4 t0 s2 l+ ]% R
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
% ~. h0 {$ c; J4 Y7 t! a+ ~ - canonicalURL=x[i].href;1 U( G% a+ J8 x0 q- @
- }& o( z( y& f% ~4 ~" A7 c7 i7 x
- }; V, t6 n+ o! Z4 ?- b' i
- }
3 d) D6 k' r. D, X' J5 R! d+ i - //Get protocol
5 I3 B; y- `5 a q - if (!canonicalURL){# @/ r+ F8 i3 E" b: B
- curProtocol = window.location.protocol.split(':')[0];
- c2 Y5 p9 b( z, f/ I% F - }- F6 ~8 g( \) t5 u& R
- else{
6 z F0 f, E- o T - curProtocol = canonicalURL.split(':')[0];
7 X' }; ?1 U7 Z. c5 y5 d2 V. l6 k - }& c* q/ f- F( z5 ?+ C
- //Get current URL if the canonical URL does not exist
- a5 Z1 g& u" g! y - if (!canonicalURL) canonicalURL = window.location.href;
l( ?3 `: I- H) z; U e+ M - //Assign script content. Replace current URL with the canonical URL# O$ U0 }/ e# s' d7 T( \
- !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);})();
# T# x" U3 m Y3 M# M( s - </script>
% w }' Q. V4 C% C- c
复制代码
. r# Q( h0 G2 y3 _ N9 b/ \2 A& L" ?6 |7 p+ k- n% z: T
% h* e- l4 g* o0 t) [+ H: q \& {4 y
|
|