Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

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

Apr 24, 2014
Introduction

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:
  
In previous articles I explained jQuery open all external links in new window,
jQuery enable / disable controls on page, jQuery enable or disable hyperlinks, jQuery Countdown timer script example, jQuery Increase or Decrease font size of website and many articles relating to JQuery and asp.net. Now 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>
Live Demo

To check live demo try to close this webpage it will ask confirmation message


Welcome to Aspdotnet-suresh.com
If you want to check live demo try to close this webpage

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Sandeep Mishra said...

This is not working in Firefox.

Gaurav said...

Nice tutorial, but it is not working in Firefox. same prob here.

Anonymous said...

Does not work with firefox

Bhavik said...

Not working in Firefox can you give new code that works perfectly in firefox.
Thanks in advance

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.