Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
976 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...