Tuesday, 19 July 2011

How to prevent a user to close the browser window using JavaScript

           You had seen in many sites if you are going to close the page one warning windows is displayed and ask "This page is asking you to confirm that you want to leave - data you have entered may not be saved." Leave Page or Stay.......... 

           If you need a alert like this it is very very simple by using the following code
<html>
<head>
<title> sample page</title>
<script type="text/javascript">
window.onbeforeunload=checkIt;
function checkIt()
{
 return false;
}
</script>
</head>
<body>
</body>
</html>

No comments:

Post a Comment