How to display onbeforeunload dialog when appropriate?
Posted
by MartyIX
on Stack Overflow
See other posts from Stack Overflow
or by MartyIX
Published on 2010-04-18T19:59:00Z
Indexed on
2010/04/18
20:03 UTC
Read the original article
Hit count: 514
JavaScript
|onbeforeunload
I've got an editor in javascript on my webpage and I would like to ask user if he/she wants to leave the page even if there are unsaved changes.
I know I can add custom message to the "onbeforeunload dialog" this way:
window.onbeforeunload = function() {
return 'You have unsaved changes!';
}
(Source) but I want to display the dialog only where there really are some unsaved changes. How to do that?
Thanks!
© Stack Overflow or respective owner