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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in finding a child window

Status
Not open for further replies.

jluost1

Programmer
Jun 8, 2001
78
US
I have read some posts here but I have not found an answer to my problem. My task is to find a window, if it exists, set focus to it; if it doesn't exists, open a new window. The problem of the following code is, if the window object has never been created and I tried to find it, I got an error (object undefined). (It is working fine after childWindow is created and closed.) How can I get around this? thanks.

================================
function findOrOpenWindow(){
if (childWindow && !childWindow.closed){
alert('ChildWindow is found.');
childWindow.focus();
}
else {
childWindow = window.open(' }
}
 
I found the answer to my own question. I need to declare a global (var childWindow = 0;) and in my test, I will change to (if (childWindow!=0 && !childWindow.closed)). That works.

Now, a further question: I want to "childWindow" be anything passed into the function so that I can use this function again and again. It should be something like the following (but it doesn't work):

================================
function findOrOpenWindow(childWindow){
if (childWindow && !childWindow.closed){
alert('ChildWindow is found.');
childWindow.focus();
}
else {
childWindow = window.open(' }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top