[英]JQuery Get Parent URL in IFrame:iframe and its parent are in Different domain
我正在努力在我的iframe中获取parenet URL(即在浏览器中显示的url)。 我父站点是gslb13.aaa.com .Inside有在我加载我的网站的iframe test.elasticbeanstalk.com
(注意两者在不同的域)Onclicking smile
链路gslb13.aaa.com
。 它将在iframe中加载test.elasticbeanstalk.com
。
要获得我尝试过的父网址
var url = (window.location != window.parent.location) ? document.referrer: document.location;
alert(url);
我在test.elasticbeanstalk.com的索引页面中获取父URL(在加载时)。 然后:
1)我点击test.elasticbeanstalk.com中的“添加”按钮转到下一个视图
2)在add.jspx中重复相同的代码以获得相同的父URL
但不幸的是我得到了test.elasticbeanstalk.com的网址(非父网址:gslb13.aaa.com)
可以任何人建议我处理这个问题吗?
你不能。
相同的原产地安全规则禁止它。 http://en.wikipedia.org/wiki/Same-origin_policy
您需要使用get请求传递父页面的URL,否则就没有可靠的方法来获取“父”URL。
你需要像这样的iframe:
<script type="text/javascript">
url = encodeURIComponent(document.location.href);
document.write('<iframe src="http://test.elasticbeanstalk.com/something.php?refer='+url+'"></iframe>');
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.