Firefox扩展 - 在两个或多个窗口之间共享共同的状态 [英] Firefox extension - Share common state between two or more windows

查看:164
本文介绍了Firefox扩展 - 在两个或多个窗口之间共享共同的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Firefox扩展。
问题是,当我打开第二个窗口(Ctrl + N)我的扩展为新打开的窗口有新的状态。
如果我在第二个窗口上作出反应或更改,它不会影响第一个窗口,反之亦然。

Ex
Firefox上安装的扩展
第一个窗口打开。我的扩展正常运作,改变状态,登录,查看数据等
然后打开第二。我的扩展到新状态我不能得到以前的状态(第一个窗口状态)。

如何保持第一和第二或其他Firefox打开的窗口相同的状态。 >

解决方案

我正确地假设你正在开发一个XUL overlay插件,而不是SDK插件吗?



在Windows之间共享状态的一种方法是使用 Javascript代码模块。一个代码模块将只加载一次(除非明确地卸载),因此将暴露相同的数据到多个窗口。请务必阅读使用代码模块共享对象。但是,请注意,因此在关闭窗口时,与代码模块相关的任何状态都必须清除,否则将会泄漏。

如果您使用的是SDK,那么您的 main.js 模块已经与代码模块。内容脚本可能使用消息传递来存储和检索你的模块的状态。


I am developing firefox extension. Problem is that when i open second window (Ctrl + N) my extension has new state for new opened window. If I reacts or changes on second window it never affect on first window or vice versa.

Ex Installed extension on Firefox first window opened. My extension proper functioning, change state, login, view data etc then opened second. My extension goes new state I cant get previous states (first window states).

How can maintain same state between first and second or other firefox opened windows.?

解决方案

Am I correct to assume you're developing a XUL overlay add-on, and not an SDK add-on?

One way to share state between windows is to use Javascript code modules. A code module will only be loaded once (unless explicitly unloaded) and therefore will expose the same data to multiple windows. Be sure to read the "Sharing objects using code modules"., However, please note that therefore when closing a window, any state associated with it and stored within the code module must be cleaned up, or would leak otherwise.

If you're using the SDK instead, your main.js module is already the equivalent of a code module. Content scripts may use message passing to store and retrieve state from your module.

这篇关于Firefox扩展 - 在两个或多个窗口之间共享共同的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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