Solved

listen to first window close

Posted on 2006-07-01
4
194 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now