FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Javascript onunload without body.

 


Dougie1
OK I am using ajax to load different pages. But once one page is navigated away from I want to run a function. How would I do this without the body tag??

Thanks. Smile
Stubru Freak
Dougie1 wrote:
OK I am using ajax to load different pages. But once one page is navigated away from I want to run a function. How would I do this without the body tag??

Thanks. Smile


addEventListener for Firefox, attachEvent for IE.
blueray
Please try this.

Code:
window.addEventListener('unload', unload_func, false);
Stubru Freak
blueray wrote:
Please try this.

Code:
window.addEventListener('unload', unload_func, false);


This only works for DOM-compatible browsers, if you want it to work in Internet Explorer:

Code:
if(window.addEventListener)
  window.addEventListener('unload', unload_func, false);
if(window.attachEvent)
  window.attachEvent('onunload', unload_func);


Note the extra argument in the DOM-function, and the inclusion of the 'on' prefix in IE.
qscomputing
Dougie1 wrote:
But once one page is navigated away from I want to run a function. How would I do this without the body tag??

Why would your page not have a body tag? Just because it uses AJAX doesn't give it an excuse not to follow the standards.
leontius
Or use a fully-packed library like jQuery to do all low-level work.
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.