Friday, 15 June 2012

Execute Javascript function before browser reloads/closes browser/exits page? -



Execute Javascript function before browser reloads/closes browser/exits page? -

is there way execute function before user chooses reload/close browser/exit page?

i need "online/offline" status function trying write. want observe whether user still on page or not.

any ideas? :)

maybe there improve approach this?

inline:

window.onbeforeunload = function(event) { // homecoming null; };

or run pre-defined function:

window.onbeforeunload = myfunction; var myfunction = function(event) { // homecoming null; }

notes:

when event returns non-void value, user prompted confirm page unload. in browsers, homecoming value of event displayed in dialog.

since 25 may 2011, html5 specification states calls window.showmodaldialog(), window.alert(), window.confirm() , window.prompt() methods may ignored during event.

see documentation @ https://developer.mozilla.org/en-us/docs/dom/window.onbeforeunload

javascript

No comments:

Post a Comment