Connecting Tech Pros Worldwide Forums | Help | Site Map

Testing to see if a window is open

Steve Karnath
Guest
 
Posts: n/a
#1: Jul 23 '05
Hello all,
I am trying to check if my new window is open and if it is change the url.
This works until I use the x in the corner to close the window. At that
point i get an error when i try to open the window again. I believe that it
is because newWindow is still active. How do I close newWindow when it is
unloaded or closed by the x. If this is truely the problem.

function openWindow()
{
if (typeof (newWindow) == "undefined" || newWindow.open == false)
{
newWindow = window.open("http://www.yahoo.com","","width=400,height=400");
newWindow.focus();
return false;
}
else
{
newWindow.location.href = "http://www.msn.com"
}
}

Here's my solution, seems a little redundant though.
function openWindow()
{
if (typeof (newWindow) == "undefined" || newWindow.open == false)
{
newWindow = window.open("http://www.yahoo.com","","width=400,height=400");
newWindow.focus();
return false;
}
else
{
newWindow.close()
newWindow = window.open("http://www.msn.com/","","width=400,height=400");
newWindow.focus();
return false;
}
}

Any help would be great, but it's not urgent as I have something that works.
Steve



bruce_brodinsky@glic.com
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Testing to see if a window is open



Steve Karnath (remove this text) wrote:[color=blue]
> Hello all,
> I am trying to check if my new window is open and if it is change the[/color]
url.[color=blue]
> This works until I use the x in the corner to close the window. At[/color]
that[color=blue]
> point i get an error when i try to open the window again. I believe[/color]
that it[color=blue]
> is because newWindow is still active. How do I close newWindow when[/color]
it is[color=blue]
> unloaded or closed by the x. If this is truely the problem.
>
> function openWindow()
> {
> if (typeof (newWindow) == "undefined" || newWindow.open == false)
> {
> newWindow =[/color]
window.open("http://www.yahoo.com","","width=400,height=400");[color=blue]
> newWindow.focus();
> return false;
> }
> else
> {
> newWindow.location.href = "http://www.msn.com"
> }
> }
>
> Here's my solution, seems a little redundant though.
> function openWindow()
> {
> if (typeof (newWindow) == "undefined" || newWindow.open == false)
> {
> newWindow =[/color]
window.open("http://www.yahoo.com","","width=400,height=400");[color=blue]
> newWindow.focus();
> return false;
> }
> else
> {
> newWindow.close()
> newWindow =[/color]
window.open("http://www.msn.com/","","width=400,height=400");[color=blue]
> newWindow.focus();
> return false;
> }
> }
>
> Any help would be great, but it's not urgent as I have something that[/color]
works.[color=blue]
> Steve[/color]
----------------------------------------------------------------------

Hey, I have some sample code, it's so old, I'm not sure it works,
but why don't you try this:

if (oWindow2==null || oWindow2.closed)
.....
where oWindow2 is the object reference (not the name of the window),
and is saved as a global javascript variable (outside any function).
This ostensibly tests to see if the window is closed.
Bruce Brodinsky

Closed Thread