Skip to content

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.

See also  [Exception... "Could not convert JavaScript" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x