I have a document that can not be quit without saving changes. I use onbeforeunload to ask user if he really wants to quit. It works fine if the “quitting” scenario is clicking on a link and reloading page. but i have also JS menu that moves user from document editor to settings and it’s done without website redirect but is handled wholly by JS by replacing “document view” and showing “edit settings view”. But moving to edit settings view makes the changes in document unsaved like a normal reload does. So how to invoke browser to ask if user really wants to move to edit settings view like it does when page reload occurs in this scenario?
Share
You can’t, without navigating away from the page. But you can ask them with a much nicer, more friendly modal dialog of your own (an absolutely positioned
divwith azIndexgreater than any other, possibly with aniframeshim under it to eat all clicks, etc.). You can roll your own, but there are lots of modal dialog libraries out there which would save you time.Or if you like, you can use
confirm, which doesn’t have a very good user experience (but then, neither doesonbeforeunload) but is dead easy to code and entirely cross-browser compatible (despite the link being to a Mozilla page).