【问题标题】:document.referrer get blankdocument.referrer 为空
【发布时间】:2013-07-16 08:56:27
【问题描述】:

我在 IIS 中将错误页面设置为 httpRedirect.htm,尝试在捕获到错误 403.4 时将任何 http 请求转换为 https。

因此,如果用户向浏览器键入 http url,它会触发 httpRedirect.htm 页面并获取此 url,将 http 替换为 https,然后重定向到此新 url。我希望这发生在 javascript 中。

但是,当我在 httpRedirect.htm 中使用 document.referrer 时,我发现它总是返回空白。

对于这种情况有什么特别的考虑吗?使用这个错误页面的浏览器能否携带上一次请求的信息?

【问题讨论】:

  • 你永远不能依赖 document.referrer。当来自书签或输入地址时,deocument.referrer 始终为空白。使用 URL 中的信息

标签: javascript html iis redirect


【解决方案1】:

您将不得不查看位置对象。重定向在服务器端。

场景:

  1. 你直接去http://example.com/index.html,然后 httpRedirect.htm 被渲染。因为那是你的第一页 访问时,referrer 为空。
  2. 您位于http://test.com/index.html 并单击链接到 http://example.com/index.html。您现在看到的是 httpRedirect.html, 但是引用者是之前的页面,即 http://test.com/index.html

由于引荐来源网址取决于您的浏览器,因此您根本无法确定引荐来源网址对象中有任何内容,即使它“应该”存在。一些防火墙和防病毒应用程序可能伪装得很好。

如果您在 http://example.com/index.html 并看到 httpRedirect.htm,那么 location.href 仍然是 http://example.com/index.html

您可以在此处查看一些使用位置的示例代码: http://kloudgate.wordpress.com/2013/05/30/how-to-redirect-http-to-https-using-iis7-0/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-28
    • 2019-10-24
    • 1970-01-01
    • 2014-04-23
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 2012-06-30
    相关资源
    最近更新 更多