小程序间通信
根据我的理解,每个小程序都是独立的实体。是否可以有 小程序间通信 ? 。如果可以的话,如何实现呢?
谢谢 J
In my understanding each applets are independent entities . Is it possible to have
inter applet communication ? . If so , how it could be achieved ?
Thanks
J
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
是的。如果小程序位于同一页面并且源自同一域,则可以实现小程序间通信。您必须首先使用属性“name=value”来命名页面中的小程序,如下
所示: 在 FirstApplet.java 中,使用上面的内容来访问 SecondApplet:
同样,您可以在 SecondApplet.java 中访问 FirstApplet
Yes. It is possible to achieve inter-applet communication if they are on the same page and originating from the same domain. You will have to name the applets in the page first using the attribute "name=value" like:
with above in place, in FirstApplet.java, use the following to access SecondApplet:
Similarly, you can access the FirstApplet in SecondApplet.java
是的。您可以使用 cookie,详情请参阅之前的答案< /a>.
Yes. You can use cookies, as detailed by this previous answer.
两个不受信任的小程序不应该能够进行通信。唯一的例外是它们是从同一网站启动的。这将允许他们使用 HTTP 请求对该站点进行通信,或者(如 @Matthew 所说)通过设置和读取本地 cookie 存储中的 cookie 进行通信。
Two untrusted applets should not be able to communicate. The only exception is if they were launched from the same website. This would allow them to communicate using HTTP requests to that site or (as @Matthew states) by setting and reading cookies in the local cookie store.
同一 Applet Context 中的两个 applet 可以很容易地进行通信。不幸的是,没有记录确定两个小程序是否处于同一上下文中。实现可能会做出令人惊讶的事情,特别是在处理错误或耗尽资源情况时。
一般来说,您应该返回到使用 LiveConnect 进行通信的浏览器,正如 Matthew Flaschen 所回答的那样。
您可以进一步与原始服务器进行通信。即使小程序是从不同的主机下载的,也可以在两个源之间建立通信路径。 HTTP,或者更好的 HTTPS,应该是与服务器通信的可靠方式。
Two applets in the same Applet Context can communicate easily enough. Unfortunately determining whether two applets are in the same context is not documented. Implementations may do surprising things, particularly when handling error or exhausted resource conditions.
Generally you should go back to the browser using LiveConnect to communicate, as Matthew Flaschen answer.
You can go further out and communicate to the originating server. Even if the applets are downloaded from different hosts, a communications path can be set up between the two origins. HTTP, or very much better HTTPS, should be a reliable way to communicate with the server.
两个小程序之间进行通信的方式还有很多。我没有考虑代码。只是提到方法,
- 使用Javascript
- 静态变量
- 单例对象
- 雷米指数
There many more ways to communicate between two applet. I am not taking into the code. Just to mentions the ways,
- Using Javascript
- Static variables
- Singleton Object
- RMI