来源:http://yi1.com.cn/posts/207

 

在js中,如果通过连接或者表单提交里,可以用以下三种方式获取上一页的url:

1、document.referrer

2、top.document.referrer

3、window.parent.document.referrer

这在ie和firefox里都可以实现

但如果在IE中用js函数跳转的话,以上三种方式得到的都是空值

 

如果当前页面嵌套有iframe的话,在iframe嵌套的文件里用js获取当前页面的上一页的url时,2和3都可以实现

但1、document.referrer 就不行,获取的是当前页面的地址

如果来源页是Javascript跳转过来的,上边的方法就拿不到了!所以用:

opener.location.href

所以,就有了下边的代码:

 

    var ref = '';
if (document.referrer.length > 0) {
ref = document.referrer;
}
try {
if (ref.length == 0 && opener.location.href.length > 0) {
ref = opener.location.href;
}
} catch (e) {}

//其它相关的:
window.location.href
window.location.pathname

var num = Math.round(Math.random()*10000);
window.location.href = (window.location.pathname)+'?'+num+';



相关文章:

  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-21
  • 2022-12-23
  • 2022-02-07
  • 2022-03-07
  • 2021-11-09
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案