473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Way to override exit button event in browser?

In my application, sometimes users accidentally click the "exit" button in the far right corner of the browser window and lose all of their unsaved work. Is there a way to prevent the window from automatically closing, and instead prompt the user if we wants to actually close it?
Aug 16 '07 #1
3 7180
acoder
16,027 Expert Mod 8TB
You can use onbeforeunload. An enhancement would be to first check if any changes have been made. If they have then ask for confirmation, otherwise just let the user close the browser.
Aug 16 '07 #2
An example of how to do this is:

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.     //Make sure the user is warned that there is data that has not been saved.
  3.     function UnloadTrigger() {
  4.         var boolChallengeClose = true;
  5.         //do checks here to see if you want to prompt them to close window
  6.         if (boolChallengeClose) {
  7.             // Return a string from this function so a popup box will be presented to the user.
  8.             // The popup box is part of the window.onbeforeunload routine.
  9.             return ("Something needs to be saved.\nDo it! :)  ");
  10.         }
  11.     }
  12.     window.onbeforeunload = UnloadTrigger;
  13. </script>
  14.  
Aug 16 '07 #3
Thanks guys. That's just what I needed.

For those reading this post in the future, I found a good example after reading the previous replies to my original question. It can be found here:

http://www.4guysfromrolla.com/demos/...nloadDemo1.htm
Aug 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: yfng | last post by:
In a web form, I want the user clicks on one button and this button will trigger another button/link which will open a new browser window? How to do that? Is there any method like...
4
by: Rithish Saralaya | last post by:
Does the tab key override the onblur event? I have a text field whose input I validate on blur, and set the focus back again if invalid. Effectively, I do not want the user to move out of the...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
2
by: jsimons | last post by:
If the user accidentally clicks the X close button I'm using the following code in the form unload event to stop them from accidentally quitting Access. Private Sub Form_Unload(Cancel As...
3
by: Publicjoe | last post by:
OK Folks, I am one confused puppy. Can someone please explain what the difference is and when to use each. I have a form with a button dropped onto it. Without actually doing anything to the...
2
by: Publicjoe | last post by:
OK Try again Can someone please explain what the difference is and when to use each. I have a form with a button dropped onto it. Without actually doing anything to the button, I next add the...
8
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for...
1
by: Vinnie123 | last post by:
In my application, sometimes users accidentally click the "exit" button in the far right corner of the browser window and lose all of their unsaved work. Is there a way to prevent the window from...
2
by: Vinnie123 | last post by:
In my application, sometimes users accidentally click the "exit" button in the far right corner of the browser window and lose all of their unsaved work. Is there a way to prevent the window from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.