PDA

View Full Version : Auto close parent popup when child popup is closed


Sonya
02-16-2003, 08:43 PM
I adapted a 'crystal ball' script from JavaScript Kit by Michael Mc Dermott.

Everything works fine. However, I would like a parent popup page to close automatically when a child popup page is closed.

Also, I would like to introduce a form 'close' button onto the child popup instead of:
newWindow.document.write("<P align='center'><A HREF='javascript:window.close()'><font size=2>Close Me</font></A></P>")
}

</script>

Everywhere I put it, the scripts fight each other to a standstill.

I read about "javascript:end" but I don't know where to put it.

Unfortunate cut and paste person!

Sonya

Adam20002
02-17-2003, 12:15 AM
is the parent pop the window that spawned the child ? If so u can just say opener.close() in the child.

So to have both fired from a button :-



<form>
<input type="button" value="Close" onClick="opener.close();window.close()";>
</form>



or something i should expect.

Adam

Beck
02-17-2003, 08:11 AM
actually, it may be more complicated than that, thanks to something that appears to resemble a security issue. You see, if you and your code aren't actually responsible for the parent popup being opened, then you can't close it unless the user choses to close it. They will be prompted whether they would like for it to close or not.

At least, that's how it's supposed to work.

Sonya
02-17-2003, 03:29 PM
Thanks Adam and Beck.

This entry now works as you said it would:

newWindow.document.write("<P></P><P></P><P align='center'><A HREF='javascript:opener.close();window.close()'><font size=2>Close Me</font></A></P>")

But I still cannot get it to work as a 'form' button.

It's no big deal I can live with it.

Have a happy!
Sonya

arnyinc
02-17-2003, 04:35 PM
Do you just want a form button to trigger this instead of a link?

newWindow.document.write("<P></P><P></P><P align='center'><input type='button' value='close' onclick='opener.close();window.close()'><font size=2>Close Me</font></A></P>")

Sonya
02-17-2003, 05:47 PM
That was exactly what I needed. I didn't realise the code didn't need <form></form>. That was the hangup.

Appreciate the final solution,
Sonya