Here’s an example of how you can create a leave page warning in JavaScript:
window.onbeforeunload = function() {
return "Are you sure you want to leave?";
};
This code creates a function that will be triggered when the user tries to leave the page. The function returns a string that will be displayed as a warning message to the user.
Please note that due to security and user experience reasons, modern browsers may ignore the message or display a generic message instead of the one returned by the function.
+ There are no comments
Add yours