0

I'm kind of new to JavaScript and I'm trying to learn how to properly use a namespace. I'm storing Windows to access them from any website file.

var myNamespace = myNamespace || {};
myNamespace.windows = [];

So anytime I open a new window I push it to the namespace array. I have It declared on a js file which I'm including on every html file, It works on my index.html but it doesn't on the other html files. How can I use the same variable across windows? Thanks.

David AK
  • 125
  • 1
  • 14
  • It would be a massive security floor if you could. – Ryan Searle May 09 '18 at 08:20
  • If you used window.open to create your windows and you're on the same domain, you can use the window.opener to access that variable. – Joschi May 09 '18 at 08:25
  • The current window is the scope of all variables in all included JS files. If you want to "share" variables across different windows then you're going to need to jump through hoops. A better question than *"how?"* would most likely be *"why?"* – Reinstate Monica Cellio May 09 '18 at 08:38
  • You could serialize the namespace to a cookie and reread the cookie on an interval on each new window you created. Alternativly you can check window.postMessage(). – Lain May 09 '18 at 08:56

1 Answers1

0

I want to access any window from anywhere without using a global array to store the windows and access it going up through openers untill i find the parent

David AK
  • 125
  • 1
  • 14
  • You can want that but it wont be possible - I mean you have to store it somewhere in the end. https://stackoverflow.com/questions/3203530/accessing-the-content-of-other-tabs-in-browser – Lain May 09 '18 at 08:52