Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > call a function on page close NOT unload

Reply
Thread Tools

call a function on page close NOT unload

 
 
Donkey Cart Racer
Guest
Posts: n/a
 
      07-05-2006
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

 
Reply With Quote
 
 
 
 
Laurent Bugnion
Guest
Posts: n/a
 
      07-05-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to close a TCP socket? (TCPSocket#close doesn't close it) IƱaki Baz Castillo Ruby 7 01-12-2010 01:32 PM
What does "Page Load" and "Page Unload", "Page Life Cycle" exactlymean???? lander ASP .Net 5 03-03-2008 02:06 PM
What happens between Page.PreRender and Page.Unload event? Mariella Bakker ASP .Net 1 05-08-2006 09:49 AM
unload for close not refresh DonO Javascript 2 03-03-2004 04:32 PM
Browser Close / New URL / Form UnLoad() Al Fraser Javascript 1 09-30-2003 04:25 PM



Advertisments