By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

call a function on page close NOT unload

P: n/a
Hi,

I have a page - page1 which opens a window1 where users can look at
tasks, in window1 users can click and open window2 where they can
create new tasks
I want to refresh window1 when window2 closes
and refresh page1 when window 1 closes
Currently i am calling a javascript function on unload which refreshes
window.opener.location
the problem i am having is that when window2 closes it unloads itself
and calls refresh on window1 which unloads itself on refresh and hence
refreshes page1
I do not want to refresh page1 when window2 closes only if window1
closes. I hope this makes sense
Is there anyway i can differenciate between unload and a page close?
because unload gets called on refresh also, and i would like to only
take actions when a page closes not wen it unloads
thanks
B

Jul 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Donkey Cart Racer wrote:
Hi,
[snip]
Is there anyway i can differenciate between unload and a page close?
because unload gets called on refresh also, and i would like to only
take actions when a page closes not wen it unloads
thanks
B
No, there is no way to differentiate between an onunload even when the
page refreshes, or when it gets closed. For the page, it's the same.

However, if window1 has a reference on window2, you can check if the
window is closed, and take appropriate action.

You can get a reference on another window either when you open it:

var myWindow2 = window.open( [url], [NAME], [FEATURES] );

and then:

if ( !myWindow2.closed )
{
// Refresh page
}

If window1 didn't open window2, and if you know window2's name, you can
use window.open to gain a reference on the already opened window:

var myWindow2 = window.open( "", [NAME], "" );

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Jul 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.