PDA

View Full Version : check if a window is closed


Ron
08-16-2002, 08:44 PM
beetle post me a sample how to check if a window is open and it works. But if I try this code it does not can any one point me to the right way please?

**************
the window will be reloaded
if the win9 is open do not open again.
..........
<head>
<title>Untitled</title>
<script>
var win9;
function openwin(){
IF(!win9.closed){
win9=window.open("http://www.we....... ");
}
return
}
</script>

</head>
<body>

<script>
openwin();
</script>

<input type="button" value="Check Pop" onClick="alert(win9.closed)">

thank you in advance

Ron

brothercake
08-16-2002, 09:06 PM
you would also need to check for the existence of the window.


if(win9) {

if(win9.closed) { .... window objects exists and is closed ... }
if(!win9.closed) { .... window objects exists and is open ... }

}

else {

... window object does not exist ...

}



Haven't tested it; but i think it's right

Ron
08-16-2002, 09:26 PM
thank you brothercake but it does not work, I guess it's because the var win9 will be always new declared if I reload the first win?


the func I use now in the <head> area looks like:

<script>
var win9;
function openwin(){
if(win9) {
IF(!win9.closed){
win9=window.open("http://www.calling-win........ ");
}
}
return
}
</script>
</head>


<!-- and the body -->
<body>

<script>
openwin();
</script>

</body>