IE中使用window.open打开新窗口时无法获取Referrer对象
在IE中,当你使用javascript的window.open方法来打开一个新的对象的时候,IE并不会自动帮你传递Referrer对象到新的窗口的,也就是说你在新窗口中使用javascript读取document.Referrer对象时只会读到空值。而且后台在HTTP请求头中也不会包含Referrer头的。例如
<a href="javascript:window.open('newurl.php?' + urlencode (document.location.toString()),'','height=200,width=150');">click here</a>
如果是我们自己做的站点,那么我们最好使用target属性来规避这个问题。如下
<a href="newurl.php" target="_blank">click here</a>
如果打算在javascript中处理Referrer信息,那么还可以通过下面的方法来获取Referrer信息
var ReferringUrl = ""; if (document.referrer) ReferringUrl = document.referrer.toString(); if (window.opener && window.opener.location) ReferringUrl = window.opener.location.toString();
如果后台代码也需要访问Referrer信息,并且必须得使用window.open方法时,那么可以将Referrer的信息作为querystring的一部分来传递
<a href="javascript:window.open('newurl.php?' + urlencode (document.location.toString()),'','height=200,width=150');">click here</a>
你可能对下面的文章感兴趣
本博客遵循CC协议2.5,即署名-非商业性使用-相同方式共享
写作很辛苦,转载请注明作者以及原文链接~
如果你喜欢我的文章,你可以订阅我的博客:-D点击订阅我的文章










最新评论
方便提供你自己的博客地址吗?你的博客是刚刚创建的吗?还是已经 创建一段时间了?
你好,按照上面的步骤完成后,搜索时空白,google.sea rch.CustomSearchControl里的id换成你 的博客的id,可以搜到,但我自己咋igoogle申请的...
你好,按照上面的步骤完成后,搜索时空白,google.sea rch.CustomSearchControl里的id...
虽然不是很懂,但还是得说声楼主辛苦了!
谢楼主分享~