Thursday, 8 May 2014

jQuery Show Alert Message before Leaving (Closing) from Web Page ASP.NET

Here I will explain how to use jQuery to show alert message before leaving from web page or jQuery show alert message while leaving from web page or closing web page using beforeunload method.

Description
 I will explain how to use jQuery to show alert message before leaving from web page.

To show alert message while leaving from webpage we need to write the code like as shown below


<script type="text/javascript">
$(function() {
$(window).on('beforeunload'function() {
return '';
});
});
</script>

If you want to see this with complete example check below code

Example


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Show Alert Message while leaving from webpage</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$(window).on('beforeunload'function() {
return '';
});
});
</script>
</head>
<body>
<form id="form1">
<div>
<b>Welcome to Aspdotnet-suresh.com</b>
</div>
</form>
</body>
</html>