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
810 views
in Technique[技术] by (71.8m points)

javascript - Difference between document.referrer and window.parent.location.href

Here's the situation: there is a site, and it belongs to the client, so it's not on my domain, lets say client.com.

On this site there is an iframe, the source of this iframe is a simple js code, which loads another js (client.js) - this code is on my domain.

What I need to do is to get the exact url of the page where the iframe is. So now I'm trying to fugure out the difference between document.referrer and window.parent.location.href with no luck.

Both give me exactly what I need, but I can't realize what is more reliable? Is there a situation, where one will work and another won't?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

document.referrer gives you the URI of the page that linked to the current page. This is a value that's available for all pages, not just frames.

window.parent gives you the parent frame, and its location is its URI.

If you want to find the URI of the parent frame, then use window.parent.location.


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

...