HighDots Forums  

OnUnLoad

Javascript JavaScript language (comp.lang.javascript)


Discuss OnUnLoad in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Simon Wigzell
 
Posts: n/a

Default OnUnLoad - 09-26-2003 , 12:41 PM






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.



Reply With Quote
  #2  
Old   
Ivo
 
Posts: n/a

Default Re: OnUnLoad - 09-26-2003 , 12:46 PM






"Simon Wigzell" <simonwigzell (AT) shaw (DOT) ca> wrote

Quote:
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




Reply With Quote
  #3  
Old   
VK
 
Posts: n/a

Default Re: OnUnLoad - 09-26-2003 , 02:09 PM



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,tru e);}
else {/* just forget it again*/}
Now do your refresh...



Simon Wigzell <simonwigzell (AT) shaw (DOT) ca> wrote

Quote:
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.





Reply With Quote
Reply




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.