|
百度站长平台链接自动提交-js代码- <script>
" y; X$ a" N) I - (function(){" K" a# u0 W- e5 [1 E
- var canonicalURL, curProtocol;
. t6 r" w! h5 o+ Y% M# c% e! W - //Get the <link> tag+ W6 a5 a+ a, }7 ]9 A; k- v
- var x=document.getElementsByTagName("link");/ [" R# O8 k# u0 f
- //Find the last canonical URL( a2 s6 Z4 w3 F# ]% F
- if(x.length > 0){9 u; R9 ~3 f; r5 k. O: Z
- for (i=0;i<x.length;i++){
2 l' Y: `8 C I# s - if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){9 j, W& [9 K8 i7 z' _
- canonicalURL=x[i].href;) D! r' a8 p0 E$ }
- }
& M) J6 ~! K" u7 ^' V* N5 ^ - }
# e8 f$ _: J5 ^- F0 g4 i/ Z - }6 o* D) s( u. L+ X
- //Get protocol
1 Q. U7 M- B. T1 m& M( |4 N3 N - if (!canonicalURL){0 Q7 i- @/ c* h. x2 M1 ~
- curProtocol = window.location.protocol.split(':')[0];8 {, m8 I" Y N6 |1 Y
- }
( z9 J7 O3 h4 { - else{
* L& x! t5 K/ [7 C: N# Q( U - curProtocol = canonicalURL.split(':')[0];
1 T3 j) k9 V* f! h4 ~& V8 n - }
( ?6 M( M; U( } C - //Get current URL if the canonical URL does not exist
3 D6 d) ~. p! Z8 Y' ^! m9 }6 M* k - if (!canonicalURL) canonicalURL = window.location.href;
5 B7 R6 {+ H% g1 p - //Assign script content. Replace current URL with the canonical URL
, X5 K9 W0 {( m" {) @" ~/ i - !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);})();
! L7 u* R3 Q; y, | - </script>
I5 i" B7 @+ V/ b* t) A2 \
复制代码 ' y3 a! h, N4 X% D! @% [5 {# v R
" t- L& H1 O! \ p3 _+ }' @! T3 A
. _" c8 r8 i' F' l$ g/ D( V
|
|