In
this article I am going to explain how to show confirmation alert before
closing browser tab using JavaScript
Description:
In
the previous article I have explained Search records from Sql Server databaseusing Linq to Sql, WCF tutorial to Insert, Bind, Edit, update and Delete therecord from sql server database in Asp.net and Display records in Gridview fromsql server database using WCF service.
When
users enter the data or update the data on webform but in between by mistake users
click on close tab and lost the all enter/update data. After all user have to
again open that particular form and again insert/update the data.
To
avoid inconvenience I am going to show a pop up message when users click on
close tab.
Implementation:
Add
the below given script in head section of page (webform, Html).
<script
type="text/javascript">
window.onbeforeunload = function () {
return 'Please save the changes
before close the tab !!!';
}
</script>
Complete HTML Markup of webform:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script
type="text/javascript">
window.onbeforeunload = function () {
return 'Please save the changes
before close the tab !!!';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<fieldset>
<legend>JavaScript Example</legend>
<h1>Show confirmation alert
before closing browser tab using JavaScript </h1>
</fieldset>
</div>
</form>
</body>
</html>
Run
the project and check it.
Demo:
In this article we have learn to how to show confirmation alert before closing browser tab using JavaScript. I hope you enjoyed this article.
No comments:
Post a Comment