Solved

listen to first window close

Posted on 2006-07-01
4
201 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

707 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