javascript - How can I ask a web user for confirmation if he really wants to leave the page? -


How can I ask the user Do you really want to leave the page?

For example, if you ask a question on the StackViewflow, click the back button?

The easiest way to do this is to pair an event handler for the "unload" JavaScript event. JQuery makes it very easy to do this with the method that you bind, you can see whether the form field of the page has text input, assuming that they pop the warning informing the user, If they navigate through the page, they will lose the unsaved data.

Whenever users go away from the page for any reason, this warning will fire.

  $ (window) .bind ('beforeunload', function () {warner (handler for .foreforeload)). ');});   

This is clearly not very user-friendly, but with some quick modifications it may be practical for your question.

Comments