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

Categories

0 votes
969 views
in Technique[技术] by (71.8m points)

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

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

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

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...