在WWW页间的沟通? [英] Inter-Page communication in WWW?

查看:172
本文介绍了在WWW页间的沟通?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使多个网页中的JavaScript之间的客户端的进程间通信?理想情况下,我想做到这一点,没有任何复杂的服务器状态更新,侦测等,并使其在客户端上完全正常工作。如果我能做出这样的跨浏览器,以及,我会在天堂哈哈。有任何想法吗?谢谢!

Is there a way to make client-side interprocess communication between multiple web pages in javascript? Ideally I'd like to accomplish this without any complex server status updating, pinging, etc. and make it work solely on the client. If I could make this cross-browser as well, I would be in heaven haha. Any ideas? Thanks!

推荐答案

有做窗口间通信的许多方面。他们是Window.postMessage,本地存储,WebRTC技术,与时下共享网络工作者。

There are many ways of doing inter-window communication. They are Window.postMessage, Local Storage, WebRTC, and nowadays Shared Web Workers.

每一个都有自己的优势/劣势:

Each of these has their own advantages/disadvantages:


  • 本地存储仅适用于相同来源的网页(原点为协议://网址:端口)。它还广播消息,在相同的起源每一个打开的窗口,所以它是缓慢的,如果你有大量的打开的页面),不幸的是,这是支持IE11和下方的唯一一个跨窗口技术。

  • 共享工人只支持Chrome和Firefox(且仅支持相同来源以及和worker.js文件必须来自同一产地加载)。您也可以'接力'的通信流量从一个网页到另一个。

  • Window.postMessage只能父/子窗口之间,但是它支持跨域!

做两个独立的网站之间的跨域通信确实是笨重。你要么必须从第一个网站执行window.open(),并使用postMessage的与第二个网站进行沟通,或者你必须设置这个错综复杂的架构,在您使用隐藏的iframe的每个站点上交谈托管的网页在同一个网站地址,而这些内部框架,然后通过本地存储或共享工人互相交谈。这就是所谓的交通枢纽。 (pretty复杂的,对吧?)

Doing cross-origin communication between two independent websites is really clunky. You either have to perform a window.open() from the first website and use postMessage to communicate with the second website, or you have to set up this convoluted architecture, where you use hidden iframes on each site to talk to a web page hosted on the same website address, and these iframes then talk to each other through Local Storage or a Shared Worker. This is called a 'communication hub'. (Pretty complicated, right?)

更糟糕的是,页面间通信一直被视为一个安全漏洞,pretty多避之唯恐不及。如果一些人有自己的方式,我想跨域的postMessage将被删除。我想看到的是一些协议的改进和创造,所以我们可以保证技术,使之合理一些OAuth的类似技术。还有的将是一个很大的未来给客户端的数据移动,和网页之间的共享将成为关键。

Worse still, inter-page communication has been seen as a security vulnerability and pretty much shunned. If some folks had their way, I imagine cross-origin postMessage would be removed. What I'd like to see is some protocol enhancements and some oAuth-like techniques created so we can secure the technique and make it reasonable. There's going to be a lot of data movement in the future to the client, and sharing it between web-pages will become critical.

这是说,不要再使车轮。有几个图书馆那里,使窗口间通信成为可能。

That said, don't re-make the wheel. There are several libraries out there that make inter-window communication possible.


  • Endpoint.js - 库(免责声明),我开发了调解在Windows之间的通信(多起源),标签,网络工作者,客户/服务器,以及IPC进程之间。它还创建一个特设的覆盖网络,允许所有的这些技术来传递信息给对方。

  • 交叉 - 实现上面的交通枢纽的做法

  • 分区计划大纲图,IWC万国表 - 臭氧的Widget框架的IPC框架。启用本地存储和PostMessage的

  • Endpoint.js - A library (disclaimer) I developed which mediates communication between windows (on multiple origins), tabs, web workers, client/server, as well as IPC between processes. It also creates an ad-hoc overlay network that allows all of these techniques to relay information to each other.
  • crosstab - Implements the 'communication hub' approach above.
  • ozp-iwc - The IPC framework from OZone Widget Framework. Enables Local Storage and PostMessage

这篇关于在WWW页间的沟通?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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