如何使用Javascript执行Iframe的跨网域网址存取? [英] How do I implement Cross Domain URL Access from an Iframe using Javascript?

查看:86
本文介绍了如何使用Javascript执行Iframe的跨网域网址存取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从位于其他网域的Iframe访问父域网址。

I need to access the Parent Domain URL from my Iframe which is in another domain.

例如:example.com是我的网站,来自其他父域(如google.com)的iframe。这里我需要从我的example.com访问父域网址。也就是说,我需要在我的example.com域中获取网址google.com。此外,父域不能硬编码。

For example: "example.com" is my website which is has an Iframe from another parent domain, such as "google.com" . Here I need to access the parent domain URL from my example.com. That is, I need to get the URL "google.com" in my "example.com" domain. Moreover, the Parent domain cannot be hard coded.

我尝试使用以下代码:

window.parent.location.href()

在访问被拒绝错误。

推荐答案

您可以尝试检查引荐来源,这应该是如果您是iframe

You can try and check for the referer, which should be the parent site if you're an iframe

,您可以这样做:

var href = document.referrer;

这篇关于如何使用Javascript执行Iframe的跨网域网址存取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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