如何使postMessage适用于所有子域 [英] How to make postMessage applicable to all subdomains

查看:130
本文介绍了如何使postMessage适用于所有子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中window.postMessage 第二个属性指定可以将消息发送到的域。有没有办法指明它适用于所有子域。

In window.postMessage second attribute specifies domain to which my message can be sent. Is there any way to specify that it is applicable to all subdomains.

尝试的事情:

iframe.contentWindow.postMessage('The message to send.','http://*.wordpress.com');
iframe.contentWindow.postMessage('The message to send.','http://wordpress.com');


推荐答案

不,不可能。

如果您知道目标iframe来自已知的有限起源集(例如http:// a。 wordpress.com,http://b.wordpress.com和http://c.wordpress.com)。在这种情况下,只需为每个源创建一个postMessage请求,因为其中只有一个会成功,而其他的将失败。

The only scenario in which you can help yourself is if you know that the target iframe is from a known, finite set of origins (e.g. "http://a.wordpress.com", "http://b.wordpress.com" and "http://c.wordpress.com"). In this case, just make a postMessage request for each of the origins, since only one of those will succeed and the other ones will fail.

这篇关于如何使postMessage适用于所有子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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