如果在<iframe>?</iframe>中单击链接,那么HTTP Referer是什么?

时间:2011-12-11 23:20:35

标签: html http iframe http-referer

假设我的网页位于http://www.website.com,其中包含<iframe>。像这样:

<html>
 <head>...</head>
 <body>
  ...
  <iframe src="http://www.washington.edu">
  ...
 </body>
</html>

现在假设有人访问www.website.com并点击iframe本身的链接(此链接位于www.washington.edu网站上)。

我的问题是在这种情况下什么是HTTP Referer?

http://www.website.com(托管iframe的网页)还是http://www.washington.edu(点击链接的网页)?

2 个答案:

答案 0 :(得分:14)

这取决于浏览器。

Firefox和Safari会将引荐来源报告为http://www.website.com,而某些版本的Internet Explorer会将http://www.washington.edu显示为引荐来源。

更新2015-04:测试上述最新版本,所有版本都将返回http://www.washington.edu

答案 1 :(得分:7)

当前浏览器

截至2015年8月,在这种情况下,所有主流浏览器(Safari,Chrome,Firefox)Referer HTTP标头设置为http://www.washington.edu


但是我鼓励您测试特定浏览器版本在特定情况下的行为,如果您的应用程序严重依赖Referer值。

我写这篇文章是因为我发现Safari 8目前为iframe中加载的JavaScript提出的Referer请求不正确,可能是因为之前曾使用不同的Referer请求此JavaScript。这是一个类似this particular one的错误,仅在2014年在Chromium关闭。(我已经向Apple报告过,顺便说一下。)

旧浏览器

历史上Internet Explorer 6 showed different behaviour than described above - 它会将Referer HTTP标头设置为http://www.website.com