February 20, 2009

Ask user before closing the browser - IE and Mozilla




If you would like to ask the user for confirmation before closing the browser , then here's how to do so. You can use this script on an ASP.NET page or a simple HTML page. The code has been tested on IE 7 and Firefox 3+


<head runat="server">


<title></title>


<script type="text/javascript">


window.onbeforeunload = function() {


if (window.event)


window.event.returnValue = 'Thank you for visiting us!';


else


return 'Thank you for visiting us!';


}


</script>


</head>



'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

3 Responses to "Ask user before closing the browser - IE and Mozilla"
  1. Gautam said...
    November 9, 2009 9:01 PM

    Hi Dear,

    Have You test your written code to ask before close the browser.

    your code is executing on every click on button or page load.

    Please i would suggest you ,Please test your written code before publish on internet.

  2. Suprotim Agarwal said...
    November 9, 2009 9:48 PM

    Gautam: The code 'has' been tested :) This code has been tested on IE7, Firefox 3 and has been added to the post.

  3. preeti said...
    December 28, 2011 2:12 AM

    Have You test your written code to ask before close the browser.

    your code is executing on every click on button or page load.

 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions