javascript - 在 IE 10+ 上,在 iFrame 中读取时 document.referrer 是否会为空?

标签 javascript internet-explorer iframe internet-explorer-11

在所有其他最新浏览器上,从 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/

相关文章:

javascript - 向事件添加回调

javascript - Json:编辑深度嵌套的值

IE(9+) 中的 Angular 2+ 问题

javascript - VBScript 单击网页表上调用嵌入式 (?) Javascript 函数的链接

css - LessCSS - 带有变量和变亮的 IE 渐变过滤器

c# - 如何将我自己的 Iframe BotFramework (dot Net) 发布到 Azure 中?

javascript - jQuery DataTables : display rows in the original data source order, 同时保持排序功能可用

javascript - 我正在尝试使用 Google Scripts 为电子表格的每一新行发布一条 Slack 消息 - 但我只收到一个帖子。我究竟做错了什么?

html - 在其他 iframe 中跨元素使用 accesskey 在 Chrome 中不起作用

html - Vimeo Embed : Custom Play Button working. 如何添加暂停按钮?