|
|
百度站长平台链接自动提交-js代码- <script>
( s) m; s4 V9 z0 Z! X& A9 } - (function(){- e' ?( [! y% |: d7 {
- var canonicalURL, curProtocol;) t. h1 o3 `' k8 j
- //Get the <link> tag
# ]7 `& X Z$ N6 U1 Q - var x=document.getElementsByTagName("link");
6 o9 z: |0 W! N8 b/ F - //Find the last canonical URL! K# q' Q+ F7 c7 `& T5 O( o l8 F
- if(x.length > 0){
8 [: m2 N5 w% z1 c7 c. d - for (i=0;i<x.length;i++){1 g6 U) U7 k# v$ ]2 P1 r E; V
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
2 A* J' ^+ z8 F - canonicalURL=x[i].href;
- F0 F% ^7 Q# e - }4 ^' ?" Y+ _* M0 p* g, `$ `
- }
5 n# f$ A( Z8 g8 i) _ - }
7 N& b% D [" h! K" g, \ - //Get protocol
+ Y( m! P$ O9 A$ Q8 w# Q+ v - if (!canonicalURL){ P* g' i/ z) K: O
- curProtocol = window.location.protocol.split(':')[0];* T9 `+ R+ D+ B* B: V6 E
- }7 t8 f2 s: y6 r& _8 o/ _# u
- else{
) @! K/ ^# D: Z4 d) O$ ~$ [ - curProtocol = canonicalURL.split(':')[0];
* m1 Q, D8 F1 Z: x+ D( A( \) t - }
2 G" W+ w: h4 d: N' j h% m+ q! [ - //Get current URL if the canonical URL does not exist% t3 W: f) N; N9 N
- if (!canonicalURL) canonicalURL = window.location.href;
. U7 m2 o5 P' A$ E& W - //Assign script content. Replace current URL with the canonical URL3 |# x& G( {1 z' c! ?& k
- !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);})();+ _! x* g/ E& G5 x! f. D
- </script>
& ~* f' p: H) r/ ]3 b
复制代码
9 [0 M8 W7 A0 K" G. e( o* R- h9 F0 u
0 X6 i8 T; c8 @ }6 C/ f1 L! ^& I4 c$ {' \
|
|