示例代码:
<script type="text/javascript"> !function(){ var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi, r=window.location.href, o=document.referrer; // console.log(e); // console.log(r); // console.log(o); if(!e.test(r)){ // 为了防止 这个网址是百度自家的产品 // console.log(‘a‘); var n="//api.share.baidu.com/s.gif"; o?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r); var t=new Image; t.src=n; console.log(t); }; // if(!e.test(‘http://www.baidu.com/‘)){ // console.log(‘a‘); // }else{ // console.log(‘b‘); // }; }(window); </script>
深入探讨:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <a href="http://127.0.0.1/1/1.html">3.html</a> <a href="http://127.0.0.1/1/2.html">2.html</a> <a href="http://127.0.0.1/1/3.html">1.html</a> <a href="http://127.0.0.1/1/4.html">2.html</a> <a href="http://127.0.0.1/1/5.html">1.html</a> <a href="http://127.0.0.1/1/6.html">2.html</a> <a href="http://127.0.0.1/1/7.html">2.html</a> <a href="http://127.0.0.1/1/8.html">2.html</a> <a href="http://127.0.0.1/1/9.html">2.html</a> <a href="http://127.0.0.1/1/10.html">2.html</a> <a href="http://127.0.0.1/1/11.html">2.html</a> <a href="http://127.0.0.1/1/12.html">2.html</a> <a href="http://127.0.0.1/1/13.html">2.html</a> <a href="http://127.0.0.1/1/14.html">2.html</a> <a href="http://127.0.0.1/1/15.html">2.html</a> <a href="http://127.0.0.1/1/16.html">2.html</a> <a href="http://127.0.0.1/1/17.html">2.html</a> <a href="http://127.0.0.1/1/18.html">2.html</a> <a href="http://127.0.0.1/1/19.html">2.html</a> <a href="http://127.0.0.1/1/20.html">2.html</a> </body> <script type="text/javascript"> var list = document.getElementsByTagName("a"); var n = "//api.share.baidu.com/s.gif"; var r = window.location.href; var url = []; for(var i=0;i<list.length;++i){ url.push(n+‘?r=‘+encodeURIComponent(list[i].href)+‘&l=‘+r); }; for(var i=0;i<5;++i){ var t = new Image; t.src = url[Math.round(Math.random() * list.length)]; }; // var m = Math.round(Math.random() * list.length); // api.share.baidu.com/s.gif?r=http%3A%2F%2F127.0.0.1%2F1%2F3.html&l=http://127.0.0.1/1/3.html // api.share.baidu.com/s.gif?r=http%3A%2F%2F127.0.0.1%2F1%2F3.html&l=http://127.0.0.1/2.html </script> </html>
谁能看出我想要实现什么功能。
原文地址:https://www.cnblogs.com/e0yu/p/9992578.html
时间: 2024-10-17 06:54:58