问题
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.?
回答1:
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.
来源:https://stackoverflow.com/questions/18358207/firefox-extension-share-common-state-between-two-or-more-windows