从跨域iframe访问父窗口变量 [英] Accessing parent window variable from an cross-domain iframe
本文介绍了从跨域iframe访问父窗口变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
内部 http://mydomain1.com/index.html
<html>
<body>
<script type="text/javascript">
var a = 1;
</script>
<iframe src="http://domain2.com/test2.html"></iframe>
</body>
</html>
内部 http://domain2.com/test2.html
<script type="text/javascript">
alert(parent.a); // forbidden
</script>
任何工作?
推荐答案
如果您需要与其他框架通信,可以使用 postMessage
。这只适用于现代浏览器(IE8,FF3,Opera 9,Chrome)。
If you need to communicate with the other frame, you could use postMessage
. This is only available on modern browsers (IE8, FF3, Opera 9, Chrome).
由于安全原因,您无法完全访问跨域框架a href =http://en.wikipedia.org/wiki/Same_origin_policy =nofollow noreferrer>同源政策)。
You cannot really have full access to cross domain frames due to the security reasons (Same Origin Policy).
这篇关于从跨域iframe访问父窗口变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文