Click to See Complete Forum and Search --> : Closing Popup when Opener window is gone
raktims
01-14-2003, 02:12 PM
Hello,
How can I close a popup window when the main window which created the popup is closed or main window moves to another page ? I need to do this thru an event handler.
Thanks,
Raktims
Charles
01-14-2003, 02:21 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
<!--
var win;
function newWin(url) {
win = window.open(url,'','height=300,width=200');
window.onunload = function() {if (!window.closed) window.close()};
return false;
};
// -->
</script>
<title>Example</title>
<p><a href="http://www.w3.org/" onclick="return newWin(this.href)">W3C</a></p>
raktims
01-14-2003, 02:42 PM
Thanks for your reply.
I am getting a problem with the code. When I close the main window a Windows dilaog box pops up to confirm if I want to close the popup window. On saying 'yes' the focus goes to the popup and it stays open. What could be wrong.
Charles
01-14-2003, 02:50 PM
I screwed up and should have posted:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
<!--
var win;
function newWin(url) {
win = window.open(url,'','height=300,width=200');
window.onunload = function() {if (!win.closed) win.close()};
return false;
};
// -->
</script>
<title>Example</title>
<p><a href="http://www.w3.org/" onclick="return newWin(this.href)">W3C</a></p>
raktims
01-14-2003, 02:51 PM
Great. Thanks. I came up with the fix at the same time. Appreciated.
raktims