I need to have a function execute on a page in one tab when certain conditions are met in another tab. All I need to do is send some kind of nudge to the other tab. I’ve tried many things already in conjunction with a timer to keep polling:
- GM_setValue (not supported in Chrome apparently)
- Setting top.item (apparently doesn’t work between tabs)
- Cookies (even though my userscripts are running in two tabs on the same domain, this doesn’t seem to work)
Any other ideas? And yes, I do need to use Chrome, even though it seems intent on thwarting me in this >.>
Since the tabs are on the same domain, you can use
localStorage.Set the script to run on both pages, EG:
Be sure you can tell which page is which. By the URL, for example, or some different content.
The sending page merely sets values as desired, EG:
The receiving page listens for
storageevents like:or
Putting it all together, here is a complete script, that works in both Firefox and Chrome (and probably Opera and others).
You can test it against this “sender” page, and this “receiver” page.