OnUnLoad

S

Simon Wigzell

I'm using OnUnLoad in my body statement to redirect to a function to clean
things up if someone exits a form by closing it from outside the webpage
code - e.g. by not using the cancel or save and exit buttons I have supplied
but by clicking on the browser window top right X or closing it by clicking
with the right mouse button on the tray icon for the window. Unfortunately
it is also triggered by a refresh, which my web page does as part of it's
functionality. Is there not a way of only trapping "improper" exiting of a
web page? Thanks.
 
I

Ivo

Simon Wigzell said:
I'm using OnUnLoad in my body statement to redirect to a function to clean
things up if someone exits a form by closing it from outside the webpage
code - e.g. by not using the cancel or save and exit buttons I have supplied
but by clicking on the browser window top right X or closing it by clicking
with the right mouse button on the tray icon for the window. Unfortunately
it is also triggered by a refresh, which my web page does as part of it's
functionality. Is there not a way of only trapping "improper" exiting of a
web page? Thanks.

Depends on why and when you refresh. Whether or not it is predictable enough
to set a variable onbeforerefresh and don't set it otherwise. Then make the
unload function check that variable before doing its thing.
Ivo
 
V

VK

On load:
....
if (Explorer) {self.attachEvent('onunload',sayByeBye);}
else if (Netscape) {self.addEventListener('onunload',sayByeBye,true);}
else {/* just forget it */}
....

Then supposing you know when you want to refresh your site (and you should
for sure!):

Before refresh:
if (Explorer) {self.detachEvent('onunload',sayByeBye);}
else if (Netscape) {self.removeEventListener('onunload',sayByeBye,true);}
else {/* just forget it again*/}
Now do your refresh...
 

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

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top