0

I have a query about communication between two different userscripts running on different pages.

If you have Script A running on Page A, and a link on Page A opens Page B that runs Script B, is there any way for Script A to send data to Script B?

Let's say for example that Page A has a link. If you open the link, Page B opens. Let's say Script A running on Page A has a button. If you click the button, then when Page B opens Script B makes the background a different colour.

How can Script B receive data from Script A assuming that each userscript is running on a separate page from each other?

My first idea was to add little codes to the URL, that doesn't affect the URL location but enables the next script to see data.

(e.g. normally www.something.com/pageB/would become www.something.com/pageB/&code or something similar. I was wondering if there's a safer way to do it.

BenMorel
  • 30,280
  • 40
  • 163
  • 285
Edge
  • 2,337
  • 5
  • 28
  • 49
  • Maybe use a `setInterval` on `Script B` to check for a certain bit of DOM that `Script A` can insert. – Milo LaMar Feb 03 '14 at 22:06
  • 1
    hash is better than search. aka fragment is better than queryString. you can also both talk to a common page, but it's probably easier to use hash or if on the same domain, localStorage. – dandavis Feb 03 '14 at 22:09
  • I was thinking specifically if you opened `Page B` with a `window.open()`. But yeah, found this http://www.nczonline.net/blog/2010/09/07/learning-from-xauth-cross-domain-localstorage/ from another question http://stackoverflow.com/questions/4177803/can-html5-databases-and-localstorage-be-shared-across-subdomains which all seems pretty nifty for that sort of thing. – Milo LaMar Feb 03 '14 at 22:17
  • I don't own the site, and let's say that Page A and Page B are different domains. – Edge Feb 03 '14 at 22:19
  • Check out the link I posted. It's a pretty neat little way to store stuff cross-domain. – Milo LaMar Feb 03 '14 at 22:20
  • I don't want to use frames. Page B is not a child of Page A. Page B needs to run separately and it likely has more than one Script attached. – Edge Feb 03 '14 at 22:23
  • http://userscripts.org/topics/129258 I guess this about covers it. – Edge Feb 03 '14 at 22:38
  • Window.postMessage may also work if Page A is opening Page B, I can get a window reference – Edge Feb 03 '14 at 22:39

0 Answers0