How to notify the user before leaving the page without filling all the details?
by Vijay[ Edit ] 2009-08-20 15:45:14
Sometimes we may want our web users when they are leaving the page without completing things on the current page.
Also sometimes even we may be filling a large form but accidently clicking a link which takes to a new site and get annoyed not to see the things filled up when we came back to the page using back button.
For that as a web developer we may use the onbeforeunload funtion to notify that they are leaving a page..
Eg:
<HTML>
<head>
<script>
function closeIt()
{
// here you can add some if conditions to check whether the user has filled all or something else
return "Your response string will appear here between the predefined text";
}
window.onbeforeunload = closeIt;
</script>
</head>
<body>
www.hiox.org</a>
</body>
</html>
The output will be a dialog displaying with the following sample message with ok and cancel button.
When the user click ok it navigates to the new page or stays at the current page when the user clicks the cancel button.
Are you sure you want to navigate away from this page?
Your response string will appear here between the predefined text
Press OK to continue, or Cancel to stay on the current page.