call a function on page close NOT unload

  • Thread starter Donkey Cart Racer
  • Start date
D

Donkey Cart Racer

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
 
L

Laurent Bugnion

Hi,
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( , [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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top