|
|
百度站长平台链接自动提交-js代码- <script>& T4 f: y# z) V+ r, l* `# k& a6 B
- (function(){
! A& T. L5 \4 @3 k. m% N. S - var canonicalURL, curProtocol;
$ Z) t$ ^2 m! K - //Get the <link> tag; S6 {( U1 L* ?# D5 o
- var x=document.getElementsByTagName("link");( w! l* Z, Z+ U0 R! v! J+ ? j( w
- //Find the last canonical URL
* N0 o3 ~! u1 j# n* ^% {- d - if(x.length > 0){
: G f0 _: a4 d - for (i=0;i<x.length;i++){
; \8 s5 W, q& D3 [4 o/ d s1 A% [ - if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){* f5 @& ?$ Q* }2 o3 K; }
- canonicalURL=x[i].href;
( N/ u: D, ?" a* F& s- F - }
( v/ j$ ?$ i- X5 ~. o/ H - }
: Q- ^& Z$ R8 l T - }
6 {% L& c7 n" d4 v - //Get protocol
, S' ~! }3 t2 ^+ {* }9 S* q. m+ u - if (!canonicalURL){
7 e$ i& d. m, v' Z; A - curProtocol = window.location.protocol.split(':')[0];
8 b. a- U. m, X$ ]$ \ - }2 Y+ n0 Q! f% {1 \4 K3 n3 k6 p
- else{
; ?% k9 b f I: t) v6 { - curProtocol = canonicalURL.split(':')[0];2 t" ~! b" u9 v. o* U: W6 H. i @
- }
% |6 J; W9 k3 o - //Get current URL if the canonical URL does not exist
0 J4 [0 Z3 H. a$ G( D0 { - if (!canonicalURL) canonicalURL = window.location.href;
+ k4 ~' @! |4 ~# e; Z9 ^& ^5 l - //Assign script content. Replace current URL with the canonical URL$ A% |5 l* ^8 f8 w& W+ c" a7 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);})();6 X! V8 I( e8 a8 L" w+ n' X; c
- </script>; h7 Z/ g8 x( C* ]# S( Z) B
复制代码 4 x* p, ^' B- ]! c% k
7 |9 b9 z! d! n) L
! ~+ K* ?2 y; {" C: v; A |
|