Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test if window is open 1

Status
Not open for further replies.

Trusts

Programmer
Feb 23, 2005
268
US
Hi,

I have a web app in which Javascript opens a number of windows. Which ones get opened depend on user actions so I can't be sure which are opened.

When the user causes a window to open, I first want to check if that window IS already open.

Is there a way to do this? I can't find anything about it.

Thanks!
 
Not unless you are storing references to the windows you open when you open them.

Thankfully there is no windows collection, otherwise unscrupulous websites would just attempt to access them to see what other Urls you may have open.







----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks Vacunita.

I am keeping a new window referenced as such:

a_height=screen.availHeight;
a_width=screen.availWidth;
var window1=window.open('1.html','Nav','location=no, menubar=no, resizable=no, scrollbars=no, status=no, titlebar=no, toolbar=no, width=a_width, height=a_height');

So in this case I have "Window1" as a reference. But now how do I check if it's already open? - meaning this particular opening line was already run.

Something like this

if (Window1 is not open) {
run the code above
}

But what is the way to code that - what syntax?

Thanks!
 
I'd use a global window array in addition to the single variable.

So every time you open a a window, you add the reference to the array.

Then you can check whether its closed.

Code:
var MyWindows=new Array();



function Myfunc(){

if(!MyWindows['winname'] || MyWindow['winname'].closed){
alert('The window was closed or doesn't exist');
}

else{
MyWindows['winname']=window.open(...);
}


}





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top