You maybe already see a confirm box with 2 buttons: Leave This Page and Stay On This Page when you try to leave current page by closing browser/tab or navigating to another page/link.
Some people think this feature is annoy as they have to click Leave this Page button all the time to close the page/tab but others think this is very useful if they’re on a form with some fields. All changes they made or information they filled would be lost if they make a mistake, no chance to roll back. Stay on this Page button will save time for people in many cases.
Display Leaving Confirm Box Leave This Page Or Stay On This Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Display Leaving Confirm Box Leave This Page Or Stay On This Page</title> <meta name="robots" content="noindex, nofollow" /> </head> <body> <script language="JavaScript"> window.onbeforeunload = confirmExit; function confirmExit() { return "You have attempted to leave this page." + "\n\n" + "The changes you made will be lost if you navigate away from this page."; } </script> </body> </html> |
Note: we can add some break lines (\n) to make the message clear and easier to understand.
So, if they made a mistake or are not sure, click Stay on this Page to stay. Or they’re sure and want to leave, click Leave this Page.