在IE 10+上,当在iFrame中读取时,document.referrer会为空吗? [英] On IE 10+, will document.referrer be blank when read inside an iFrame?
问题描述
在所有其他最近的浏览器中,从在iframe内运行的应用程序中读取 document.referrer
将返回父站点的URL。但是,在IE 11上,它似乎返回一个空字符串。我想确认这是否是IE 10+的预期行为,但谷歌搜索并没有出现太多关于这种特殊情况。
On all other recent browsers, reading document.referrer
from an app which runs inside an iframe would return the URL of the parent site. On IE 11, however, it seems to be returning an empty string. I want to confirm whether this is the expected behaviour on IE 10+, but googling hasn't turned up much about this particular scenario.
MS的文档有点模糊:
仅当用户通过前一个文档中的链接到达当前文档时,此属性才返回值。否则,document.referrer返回一个空字符串;
This property returns a value only when the user reaches the current document through a link from the previous document. Otherwise, document.referrer returns an empty string;
我不知道上面是否包含iFrame,然后有这一点:
I don't know if the above covers iFrame's or not, and then there is this bit:
当链接来自安全网站时,它也会返回一个空字符串。
it also returns an empty string when the link is from a secure site.
父应用确实是一个安全的https网站,但我们的iframe应用也是如此。这是否意味着我们将无法在IE 10+上的iframe中读取此属性?谢谢
The parent app is indeed a secure https site, but so is our iframe app. Does this mean that we won't be able to read this property from within our iframe on IE 10+? Thanks
推荐答案
我发现 document.referrer
属性是当iframe没有 src
或者 javascript:
协议时,它的 src
。
I've discovered that the document.referrer
property is also an empty string when an iframe has no src
or a has a javascript:
protocol for its src
.
您可以在开发人员工具中轻松验证这一点:
You can verify this quite easily in the developer tools:
var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
ifr.contentDocument.referrer;
//-> '' in IE, '<parent location>' in Chrome
这篇关于在IE 10+上,当在iFrame中读取时,document.referrer会为空吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!