简体   繁体   English

嵌套的iframe跨域通信

[英]Nested iframe cross-domain communication

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. 这有两种情况:大写作为一个域,小写作为另一个域1.假设窗口A容纳iframe b,而窗口b容纳iframe C,A和C在一个域中(较高的隐私性),而b在另一个域中。 Is there any direct way for communication between A & C, oneway or twoway. A和C之间有单向或双向通信的直接方式。 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. 2.假设A拥有iframe b和iframe c,A在一个域中,而B&C在另一个域中,这与第一种情况中概述的问题相同。

I will really appreciate your answer, it will be better if with some javascript codes Thanks 非常感谢您的回答,如果使用一些javascript代码,效果会更好

Yes if they are deliberately cooperating. 是的, 如果他们有意合作。 HTML5 includes the postMessage API for this purpose, and it's implemented in IE8, FF3.5, Chrome, Opera, etc. For downlevel browsers, a "hack" called Fragment Messaging can be used. HTML5为此包含了postMessage API,并且已在IE8,FF3.5,Chrome,Opera等中实现。对于下层浏览器,可以使用称为“碎片消息”的“ hack”。 If you use Flash, you can use Flash Local communication channels. 如果使用Flash,则可以使用Flash Local通信渠道。

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. 您需要发出HTTP请求以实现它们中的任何一个。

  1. Pass the information in the URL when loading the page 加载页面时在URL中传递信息
  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. 对于使用<script>元素加载的信息,从远程域加载的JS文件中的任何代码都将在其中包含<script>元素的页面中运行。

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 . 参见JSON-P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM