简体   繁体   English

Javascript:框架之间的通信

[英]Javascript: communications between frames

I have two different applications loaded into different frames. 我有两个不同的应用程序加载到不同的框架。 I need them to communicate I know that javascript security model does not allow frames loaded from different domains to communicate but since I control both applications maybe there is a way to allow frames loaded from specific another domain to communicate with this frame 我需要它们进行通信,我知道javascript安全模型不允许从不同域加载的框架进行通信,但是由于我同时控制两个应用程序,因此也许有一种方法可以允许从特定其他域加载的框架与该框架进行通信

If it is not possible what's the hack around? 如果不可能的话,那该怎么办? Apps are different and I need to load them at different domains (or at least different ports) I can not run them as one app 应用程序不同,我需要将它们加载到不同的域(或至少是不同的端口),我无法将它们作为一个应用程序运行

If they share top-level domain (eg foo.example.com and bar.example.com ), then you can set document.domain = 'example.com'; 如果他们共享顶级域(例如foo.example.combar.example.com ),则可以设置document.domain = 'example.com'; to relax same-origin restriction . 放宽原产地限制

If you support only HTML5 browsers, then there's postMessage() exactly for cross-domain communication. 如果仅支持HTML5浏览器,则存在用于跨域通信的postMessage()

Other options are JSONP (fancy name for a cross-domain <script> tag) and proxying of XmlHttpRequest via the server on each domain. 其他选项包括JSONP (跨域<script>标记的别名)和通过每个域上的服务器代理XmlHttpRequest

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

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