|
|
How to notify the user before leaving the page without filling all the details? - Javascript
|
Views : 599
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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.
|
|
By Vijay, On - 2009-08-20 |
|
|
|