I have a html page. In the body of the page I am calling onload
event which calls javascript function to open a pop up window. here is the code:
var newWindow = null; function launchApplication() { if ((newWindow == null) || (newWindow.closed)) { newWindow = window.open('abc.html','','height=960px,width=940px'); } }
when I move to another page, and come back to that page again, popup reopens, although it is already opened. Please guide me to proper direction so that if pop up is already open then it should not open again. I tried document.referred
but it requires the site online, currently I am working offline.
Here is the code: var win = window. open('http://www.google.com', 'google','width=800,height=600,status=0,toolbar=0'); var timer = setInterval(function() { if(win. closed) { clearInterval(timer); alert('closed'); } }, 1000);
If you store a reference to the child window when you call window. open() , then you can poll using setInterval() to see whether the window is still open using the window. closed property.
When you open a page in a new tab or window, the web browser creates a new session. If you open multiple tabs or windows with the same URL, the web browser creates a separate sessionStorage for each tab or window.
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="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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With