Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnUnload problem

Status
Not open for further replies.

davem99

Programmer
May 19, 2003
74
US
Hi - I have a page which opens a popup window when it closes using the OnUnload event.

My problem is that this event fires on Refresh / F5 as well as any POST on my page.

ANy ideas how I can achieve this?

Thanks!!
 
Have you considered that browsers to your site may not want a pop up window opening on thier computer?

If it happens to me - my first visit to your site would be my last.

Just my opinion.

Simon
 

You can't stop a page refresh from running onUnload, while still having the event run on a proper unload.

Sorry!

Dan
 
Just some musing on my part. Couldn't you set a cookie on load and use that to stop the onunload function from happening on refresh. I have a page that sets a cookie so that when a user returns to a page an onload function doesn't fire, couldn't it work for onunload as well?

Glen
 

How do you suggest detecting that the page has been refreshed, instead of unloaded?

AFAIK, you cannot tell the difference using scripting.

Dan
 
Well one way would be to use onkeypress (f5) I guess. of course that wouldn't work if the user used a menu. Interesting problem!! Sorry if I'm off base here but there must be a way.

Glen
 
Thanks everyone for the input....it still seems that this is a difficult thing to achieve......that amazes me!

I'm sure I can't be the first person to want to do this...
 
This works in IE (haven't tested it anywhere else...)

var Leaving = true;
function leave() {

if ((window.screenTop > 10000) && (window.screenLeft > 10000)) {
/*...code here to open a window to perform cleanup on the host side - since this block is executed only when the browser is being closed */
}
else {
if(Leaving){
/* code here will be called for all other unload situations - you can add onclick='Leaving=false' to your own links that are not leaving your site */
alert('Now leaving ' + window.location.hostname);

}else{
// nothing
}
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top