?
Solved

listen to first window close

Posted on 2006-07-01
4
Medium Priority
?
205 Views
Last Modified: 2008-03-06
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.
0
Comment
Question by:idOle
2 Comments
 
LVL 12

Expert Comment

by:jessegivy
ID: 17025169
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
 
LVL 63

Accepted Solution

by:
Zvonko earned 200 total points
ID: 17027787
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question