简体   繁体   English

两个Web浏览器窗口之间的通信

[英]Communication between two web browser windows

I need to create web application which must have two separate web browser windows to comfort usage. 我需要创建一个Web应用程序,该应用程序必须具有两个单独的Web浏览器窗口以方便使用。 And events on each of them must cause action on another. 每个事件都必须引起另一个事件。 The app will be on html5, perhaps with websockets on client side and Java with glassfish on server side. 该应用程序将在html5上运行,可能在客户端使用websockets,在服务器端使用Java和glassfish。 Is there any way to cross browser window communication or some another solution for this problem? 是否有任何方法可以跨浏览器进行窗口通信或其他解决方案?

Yes, I described a lot of ways here: 是的,我在这里描述了很多方法:

How is it possible to share single js resource between browser tabs? 如何在浏览器选项卡之间共享单个js资源?

If the browser support is not so important for you, then you can use shared webworkers . 如果浏览器支持对您不是很重要,则可以使用共享的webworkers The next option to use storage event to exchange data, one implementation is intercom.js for that. 使用存储事件交换数据的下一个选项是intercom.js The most supported way to use cookies BNC Connector does that. 使用cookie的最受支持的方式是BNC连接器

The best way to solve this problem is to store the information on the server side and have the web application communicate with the server (with JavaScript I expect). 解决此问题的最佳方法是将信息存储在服务器端,并使Web应用程序与服务器通信(我希望使用JavaScript)。

You can have the web page "poll" the server every set period (eg 5 seconds) to see if there is an event or message to handle. 您可以在每个设置的时间段(例如5秒)使网页“轮询”服务器,以查看是否有事件或消息要处理。

I used postMessage before - but not very heavily, worth a shot. 我以前使用过postMessage但不是很沉重,值得一试。
See post and demo at: http://robertnyman.com/2010/03/18/postmessage-in-html5-to-send-messages-between-windows-and-iframes/ 请参阅以下网站的发布和演示: http : //robertnyman.com/2010/03/18/postmessage-in-html5-to-send-messages-between-windows-and-iframes/
Also see http://benalman.com/projects/jquery-postmessage-plugin/ for jQuery postMessage 另请参阅http://benalman.com/projects/jquery-postmessage-plugin/有关jQuery postMessage的信息

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

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