0

I want to open a window with JS on a page (the page contains an editor) and you can add items to this editor from the website where there are buttons "add to editor".

When a user clicks an "add to editor" button I want to determine if the editor is already open and if so execute some JS on that (so I can add it) or open a new window with the editor.

When I use the following code:

window.open('/editor', 'editor');

This works fine for opening a window named editor. But when someone has the editor open and clicks the same button on another page, the editor is refreshed which is not what I want.

I can't store the window.open result in a variable (e.g var foo = window.open() ) since that only works on one page. Is there another way to do this?

If it is easier with jQuery, I am using that too. So that is a possibility.

Matthijn
  • 3,126
  • 9
  • 46
  • 69
  • @Frédéric Hamidi, I don’t think this is a duplicate – the other question is simply about how to access windows by name in general; but this one here has the added limitation of trying to only access popup windows from their opener window, but not overwrite their contents from different tabs. – CBroe Aug 18 '14 at 14:38
  • @CBroe, [this answer](http://stackoverflow.com/a/18542652/464709) and [that one](http://stackoverflow.com/a/22241067/464709) provide a solution to check if a window is already opened, by name. That would allow the questioner to prevent refreshing the document if the popup is already open, which I believe answers their question. – Frédéric Hamidi Aug 18 '14 at 14:43
  • @Frédéric Hamidi: No, he _wants_ to refresh the popup if the request comes from the same tab that it was opened from. If the user has the website/app open in more than one tab though, he does _not_ want the click on the button to refresh the existing popup, but open a new one. (Popups have the same name here, even if they are opened from different tabs. And that is what he’s looking to solve somehow.) – CBroe Aug 18 '14 at 14:54
  • @CBroe, that's... not how I understand it, but I may very well be wrong here. Matthijn, is CBroe's understanding correct? If it is, I will reopen the question. – Frédéric Hamidi Aug 18 '14 at 15:11
  • I'm reading it the same as CBroe. – Gabe Sechan Aug 18 '14 at 15:17
  • 1
    I'm sorry for not being clear, but I think the other one is a duplicate. I want to access one window which is opened through javascript on any other page of the website. But that doesn't seem to be possible. – Matthijn Aug 18 '14 at 17:51

0 Answers0