【问题标题】:Document.referrer issue on IE when the requests doesn't come from a link [duplicate]当请求不是来自链接时,IE 上的 Document.referrer 问题[重复]
【发布时间】:2011-05-01 19:52:18
【问题描述】:

可能重复:
IE has empty document.referrer after a location.replace

你好,

我在 IE 中使用 document.referrer 属性时遇到问题。当我不是通过链接而是通过 JavaScript 更改 window.location 到达页面时,目标页面的 document.referrer 在 IE7/8 中为空。关于如何绕过它的任何想法?

谢谢。

【问题讨论】:

    标签: javascript internet-explorer cross-browser document


    【解决方案1】:

    将旧页面 url 存储在 cookie 中。

    或者在片段标识符的url中添加referer。

    location.href = 'page.html' + '#' + location.href
    

    或者使用 javascript 即时创建一个链接,并将其称为 .click()。所以像

    var a = document.createElement('a');
    a.href='page.html';
    document.body.appendChild(a);//not sure if this is needed
    a.click();
    

    【讨论】:

    • 谢谢 Gerben……它真的帮了我很多……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    • 1970-01-01
    • 2022-11-10
    相关资源
    最近更新 更多