listen to first window close

Hi,

I am trying to animate the size (or position) of a window that is opened up by another window when the opener is closed by the user (or when the url is changed in the opener). The second window can be opened at the same time the first page is launched or can be poped up when the first window is closed.

My question is:

how do I listen to the "onclose" event of the first window from within the second window?

Thanks.
idOleAsked:
Who is Participating?
 
ZvonkoConnect With a Mentor Systems architectCommented:
LOL :-)
Sorry Jesse, but I think you will also lough about your proposal when you read it later ;-)

"how do I listen to the "onclose" event of the first window from within the second window?"
The answer is: you cannot listen to onclose, you have to pool at an interval to notice that the opener is closed.
OR, you can be notified by the opener that he is going to be closed by the onUnload event handler.
Like this:
<script>
var popup;
function openPopup(){
  popup=window.open("yourpopup.htm");
}
</script>
<body onUnload="if(popup)popup.yourFunctionToBeExecutedOnParentClose()">

On IE you cane better use onBeforeUnload for that popup window function call.

0
 
jessegivyDeveloperCommented:
You can create a global javascript variable in the opener that contains a reference to the first popup, then reference that within the second window.  Like this:

<script type="text/javascript">
var popup;
function openWindow1()
{
    popup=window.open("source","name","properties");
}
</script>

...then in the second window you can reference the popup variable and check to see if it contains a reference to a window that's been closed.

if(window.opener.document.popup.closed())
{
    //resize window or do whatever ya want???
}

cheers,

Jesse
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.