Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
910 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...