Check if window is already open window.open

newWindow = window.open('abc.html','com_MyDomain_myWindowForThisPurpose','height=960px,width=940px');

Give the window a name. Basing the name on your domain like this, prevents the chances of you picking a name someone else happened to choose.

Never make up a name that begins with _, those are reserved for special names the browser treats differently (same as with the “target” attribute of anchor elements).

Note that if the window of that name was opened with different options (e.g. different height), then it’ll keep those options. The options here will only take effect if there is no window of that name, so you do create a new one.

Edit:

Note that the “name” is of the window, not of the content. It doesn’t affect the title (newWindow.document.title will affect that, as of course will code in abc.html). It does affect other attempts to do stuff across windows. Hence another window.open with the same name will reuse this window. Also a link like <a href="https://stackoverflow.com/questions/12138236/def.html" target="com_MyDomain_myWindowForThisPurpose">clicky!</a> will re-use it. Normal caveats about browsers resisting window-opening in various scenarios (popup-blocking) apply.

Leave a Comment