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

Multiple Conditionals

Status
Not open for further replies.

pygmalion3

Technical User
Joined
Dec 28, 2001
Messages
7
Location
US
I've been trying to create a javascript function that goes through a series of conditionals to check for specific open windows, and, provided they're there, re-focus them.
Here's part of the script I'm using:

function recallPopUps(){
if ( (! (typeof firstWin == "undeclared") ) && ( ! firstWin.closed ) ) {
firstWin.focus()
}
if ( (! (typeof secondWin == "undeclared") ) && ( ! secondWin.closed ) ) {
secondWin.focus()
}
if ( (! (typeof thridWin == "undeclared") ) && ( ! thirdWin.closed ) ) {
thirdWin.focus()
}
if ( (! (typeof fourthWin == "undeclared") ) && ( ! fourthWin.closed ) ) {
fourthWin.focus()
}
}

The problem I'm having is if firstWin is not open, thus undefined, I get a "firstWin Undefined" error, and the script halts right there, not checing the other conditionals. However, if firstWin IS open, it'll go right on to the next conditional where it does the same thing. If ALL windows are open, it works great, but what am I doing wrong to a) get an undefined error and b) not getting the script to check each conditional regardless of if the one prior is true.

Little help?
 
check for firstWin.open before !firstWin.closed too:
Code:
if ( (! (typeof firstWin == "undeclared") ) && (firstWin.open) && ( ! firstWin.closed ) ) { 
firstWin.focus()
}

...and similar for the rest of the windows.
 
when the firstwin is not open, the object is obviously not known, so u get the error. the code wont proceed as long as there is error in that line. try to check for the open condition of the windows bfore u actually call its other methods.

luv
Karthik.
 
I'm not entirely sure how I can check for the window's condition without asking it to recognize the window's name to begin with. If I ask it to check firstWin.open or !firstWin.closed, I still get the undefined error. I've tried defining the name in the same script as firstWin = //nothing, so that it has SOME kind of definition, and can be re-defined by the firstWin = window.open function in the same script I have referenced from an href in another window... but to no effect.

I'm baffled. What am I doing wrong? All I need is for the code to look at "firstWin" and say, "nope, not there" and move on...

Much thanks for you guys' help. I'd be lost w/o it! :D
pyg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top