document.referrer和window.parent.location.href之间的区别 [英] Difference between document.referrer and window.parent.location.href

查看:1481
本文介绍了document.referrer和window.parent.location.href之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况如下:有一个网站,它属于客户端,所以它不在我的域名上,假设 client.com

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.

在这个网站上有一个 iframe ,这个 iframe 的来源是一个简单的js代码,它加载另一个js( client.js ) - 这段代码在我的域名上。

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.

我需要做的是获取iframe所在页面的确切网址。所以现在我试图弄清楚 document.referrer window.parent.location.href 之间的区别没有运气。

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?

推荐答案

document.referrer 为您提供链接到当前页面的页面的URI。这是一个可用于所有页面的值,而不仅仅是帧。

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 为您提供父 frame ,其位置是它的URI。

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

如果你想找到URI的父框架,然后使用 window.parent.location

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

这篇关于document.referrer和window.parent.location.href之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆