Link to home
Start Free TrialLog in
Avatar of coletteck8
coletteck8

asked on

close popup at page unload

how do i close a popup when the user leaves that page? i am using the popup function below:
<script language = "javascript">
function popup()
{
var win
win = window.open("HelpFile/alert.htm", "Help", "width = 500, height = 300, top = 50, left = 450, scrollbars = no, resizable = no");
}
</script>
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cLFlaVA
cLFlaVA


Something like this in your body tag:

<body onunload="if (win && !win.closed) { win.close(); }">

Apologies Zyloch.
Avatar of coletteck8

ASKER

i'm getting an error win undefined
this is what i have
<script language = "javascript">
function popup()
{
var win;
win = window.open("HelpFile/alert.htm", "Help", "width = 500, height = 300, top = 50, left = 450, scrollbars = no, resizable = no");
}
</script>
<body onunload = "if (win &&!win.closed){win.close();}">
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No prob, cLFlaVa, I'm just experiencing an onrush of questions after two weeks of very difficult school lol

Hmm... It should work. Try this:

if (Help && !Help.closed) {Help.close();}

But before should work. Make sure that your popup opens before you close.
Ah, so now it's my turn cL :)
hehe
OF course. i'm losing my mind here! thanks so much to both of you.