如何使postMessage适用于所有子域 [英] How to make postMessage applicable to all subdomains
问题描述
在中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屋!