嵌套iframe跨域通信 [英] Nested iframe cross-domain communication

查看:323
本文介绍了嵌套iframe跨域通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有两种情况:
大写作为一个域,小写作为另一个
1.设置窗口A保存iframe b,b保存iframe C,A& C在一个域(更高的隐私),而在另一个域。是否有任何直接的方式进行A& C,单间或双人间。
2.Suppose A保存iframe b和iframe c,A在一个域中,而B&



我会非常感谢你的答案,如果使用一些JavaScript代码,它会更好
感谢

解决方案

。由于同一来源政策,不同域上的框架之间的客户端通信是不可能的。 p>

如果可以的话,你可以做一些事情,例如将一个银行网站加载到一个框架中,填充整个窗口,然后轮询它以查看用户是否在用户名中输入了任何内容和密码字段。



如果要在域之间进行通信,则有两种方法。


  1. 在载入网页时传递网址中的资讯

  2. 对于使用< script> 元素加载的信息,来自远程域的加载的JS文件中的任何代码都将在页面中运行, c $ c>< script> 元素。

/ p>

 < script 
type =text / javascript
src =http: com / script.cgi?data = foo; more_data = bar>
< / script>

请参阅 JSON-P


Here are two cases: Uppercase as one domain while lowercase as another 1.Suppose window A holds iframe b, and b holds iframe C, A & C in one domain(higher privacy) while b in another. Is there any direct way for communication between A & C, oneway or twoway. 2.Suppose A holds iframe b and iframe c, A is in one domain while B & C in other, just the same question as outlined in the first case.

I will really appreciate your answer, it will be better if with some javascript codes Thanks

解决方案

No. Client side communication between frames on different domains is not possible due to the same origin policy.

If it was possible, you could do things like loading a bank website into a frame which fills the entire window, and polling it to see if the user has typed anything in the username and password fields.

If you want to communicate between domains, then there are two approaches. You need to make an HTTP request to achieve either of them.

  1. Pass the information in the URL when loading the page
  2. For information loaded using a <script> element, any code in the loaded JS file from the remote domain will run in the page with the <script> element in it.

You can combine the two approaches:

<script 
  type="text/javascript" 
  src="http://example.com/script.cgi?data=foo;more_data=bar">
</script>

See JSON-P.

这篇关于嵌套iframe跨域通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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