在所有其他最新浏览器上,从 iframe 内运行的应用程序读取 document.referrer
将返回父站点的 URL。然而,在 IE 11 上,它似乎返回一个空字符串。我想确认这是否是 IE 10+ 上的预期行为,但谷歌搜索并未发现太多有关此特定场景的信息。
MS documentation有点模糊:
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,然后有一点:
it also returns an empty string when the link is from a secure site.
父应用程序确实是一个安全的 https 站点,但我们的 iframe 应用程序也是如此。这是否意味着我们将无法在 IE 10+ 上从 iframe 中读取此属性?谢谢
最佳答案
我发现,当 iframe 没有 src
或具有 javascript:
时,document.referrer
属性也是空字符串> 其 src
的协议(protocol)。
您可以在开发者工具中轻松验证这一点:
var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
ifr.contentDocument.referrer;
//-> '' in IE, '<parent location>' in Chrome
关于javascript - 在 IE 10+ 上,在 iFrame 中读取时 document.referrer 是否会为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24169219/