How to Confirm before Leaving Page in Javascript

You can implement a function to be called before the user leaves a page with Javascript as follows:

window.onbeforeunload = function(e) { return "Do you want to exit this page?"; };
Code language: JavaScript (javascript)

This is a typically solution for when you want the user to confirm their changes are saved before allowing them to close the current page in editing tools.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments