JavaScript document.referrer

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4145534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:29:33  来源:igfitidea点击:

JavaScript document.referrer

javascript

提问by Ali Beasley

I've got two webpages one

我有两个网页 一个

<html>
  <body>
    <p><a href="page2.html">Link</a></p>
  </body>
</html>

And the second page.

还有第二页。

<html>
  <body>
    <script type="text/javascript">
      document.write(document.referrer);
    </script>
  </body>
</html>

The second page is always blank, it doesn't seem to be picking up the referrer, any idea's why?

第二页总是空白,似乎没有找到推荐人,知道为什么吗?

回答by Pekka

In IE, document.referrerworks only for http://resources, not https://and file://ones. Maybe that is your problem.

在 IE 中,document.referrer仅适用于http://资源,而不适用于https://file://。也许那是你的问题。

Edit:There are even more casesin which IE doesn't pass it on.

编辑:更多情况下IE 不传递它。

回答by 565

Actually document.referrer which you used will return requesting page URL for all browsers except for Internet Explorer., it actually returns null in the IE.

实际上,您使用的 document.referrer 将返回除 Internet Explorer 之外的所有浏览器的请求页面 URL。它实际上在 IE 中返回 null。