PDA

View Full Version : dependant child windows...


Dr. Web
06-19-2001, 02:17 PM
The following script creates a pop-up. This pop-up will close if the parent window is closed. So far, so good. But, the problem lies in that if the child window is not present, then a javascript error is generated, stating that the variable win is undefined. It is, because the pop-up is not open. The goal here is to use the pop-up as a help page. If the surfer exits the main page, while the help pop-up is open.... it should close too. If the surfer exits (and the help pop-up is not open) nothing happens.

Just need some ideas! Thanks in advance!

<html>
<head>
<title>Untitled</title>
<script language ="javascript">
function pop_up(){
win = window.open("http://www.yahoo.com", "dep", "height=1,width=1", hotkeys="no");
}
function closeDep() {
if (win && win.parent && !win.closed) win.close();
}
</script>
</head>
<body onUnload="closeDep();">
<a href="#" onclick="pop_up();">Yahoo</a>
</body>
</html>

Dr. Web
06-19-2001, 02:46 PM
ok, heres the new code, ravamped.

The goal: To allow users to open a pop-up type help page that automatically closes when the user leaves the main page. Why? If the user leaves the website, all pop-up windows should be closed.... a kind of 'clean-up' as they exit. Just a courtesy in some cases, in others is makes sure the surfer's session truly dies.

<html>
<head>
<title>Untitled</title>
<script language ="javascript">
win="";
function pop_up(){
win = window.open("http://www.yahoo.com", "dep", "height=100,width=200", hotkeys="no");
}
function closeDep() {
if (win=="undefined"){}else{
if (win.open) win.close();
}
}
</script>
</head>
<body onUnload="closeDep();">
<a href="#" onclick="pop_up();">Yahoo</a>
</body>
</html>