On IE 10+, will document.referrer be blank when read inside an iFrame?

孤人 提交于 2019-12-20 03:52:55

问题


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's documentation is a bit vague:

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;

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.

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


回答1:


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


来源:https://stackoverflow.com/questions/24169219/on-ie-10-will-document-referrer-be-blank-when-read-inside-an-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!