|
|
百度站长平台链接自动提交-js代码- <script>
; O$ g5 Y7 ~ E - (function(){* F* D; }; F7 K
- var canonicalURL, curProtocol;6 N f' r) q( ~( `1 m! j
- //Get the <link> tag
s) L0 f, R: r9 p' A8 \ - var x=document.getElementsByTagName("link");3 Y }' _0 D* t3 u- w% g
- //Find the last canonical URL2 A0 \6 G1 B* s! L0 s! i7 Q' m( B4 `$ ]- ]
- if(x.length > 0){
8 C: m+ z! w+ T6 \9 N) S( n - for (i=0;i<x.length;i++){4 B0 T4 \9 N5 x* J$ N6 Z2 w
- if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
3 ~8 k* S2 N% s- |2 k" c - canonicalURL=x[i].href;
, A4 w6 @& b+ \. l6 n5 P - }6 b6 B$ d% y; G
- }
" c6 }0 m# n* b' k! v5 D - }
1 J. B+ s* O8 w3 F - //Get protocol
/ Z0 ~! Y6 L' P) Q! H% H6 B - if (!canonicalURL){& v& a* ]$ _4 }) {
- curProtocol = window.location.protocol.split(':')[0];* N8 t, w" i3 d% _/ n
- }
# ^9 L0 ]. A9 M5 ~) r) | - else{( Q3 [" k" `. p/ c. v
- curProtocol = canonicalURL.split(':')[0];; Q/ C1 j$ _, X$ L$ u5 f9 {
- }
6 f0 l& h- c* _, @2 D' j' B3 u - //Get current URL if the canonical URL does not exist
, |/ |; R5 @: h P$ Q7 R- u2 D - if (!canonicalURL) canonicalURL = window.location.href;
' W }: R# p- u0 U# n/ w - //Assign script content. Replace current URL with the canonical URL
5 }6 j" V. h Z9 ^ - !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);})();% ^5 U+ r- |& p+ ~& m
- </script>9 e1 j3 ?- E, y& [! S4 y
复制代码
8 Y! E2 R3 Z n# x& Q$ R
- s4 {3 [, ~2 e% l+ x" E, a
; [7 `4 H+ G) r$ h2 j$ W |
|