Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
149
rated 0 times [  150] [ 1]  / answers: 1 / hits: 86799  / 12 Years ago, mon, august 27, 2012, 12:00:00

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.


More From » html

 Answers
74
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.


[#83412] Friday, August 24, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denism

Total Points: 627
Total Questions: 96
Total Answers: 98

Location: Ivory Coast
Member since Sun, Mar 7, 2021
3 Years ago
;