473,652 Members | 3,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

alert with "YES" and "NO" button

7 New Member
Hi every body,

i need a snippet in JavaScript to perform close window(browser)
when we close window it should give alert with "YES" & "NO" button if yes the window should stay still otherwise window should close
Sep 19 '08 #1
4 9519
senthilkumarb
7 New Member
Hi every body,

i need a snippet in JavaScript to perform close window(browser)
when we close window it should give alert with "YES" & "NO" button if yes the window should stay still otherwise window should close
Sep 19 '08 #2
Rsmastermind
93 New Member
Hi this is your solution the internet Explorer itself provides the confirm() functionality where you can find the two buttons ok and cancel and the corresponding code on the basis of input is shown below with the example

You should call this function on the event onunload

like this
Expand|Select|Wrap|Line Numbers
  1. ///////////////////
  2. <body onunload="windowClose();"
  3. ////////////////////////////////////////////////
  4.  
  5.  
  6. <script type="text/javascript">
  7. function windowClose()
  8. {
  9. var r=confirm("Window will be closed do U want to Proceed");
  10. if (r==true)
  11.   {
  12.             top.close();  
  13.   }
  14. else
  15.   {
  16.          (Do whatever you like);
  17.   }
  18. }
Sep 19 '08 #3
bnashenas1984
258 Contributor
Hi
I think you have posted your question in the wrong forum BUT anyway , here is your answer:

Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3.     var myclose = false;
  4.     function ConfirmClose()
  5.     {
  6.         if (event.clientY < 0)
  7.         {
  8.             event.returnValue = 'Are you sure you want to close this window!';
  9.             setTimeout('myclose=false',100);
  10.             myclose=true;
  11.         }
  12.     }
  13. </script>
  14. </head>
  15. <body onbeforeunload="ConfirmClose()">
  16. </body>
  17.  
  18.  
  19.  
Please note that this code only works for IE.
Sep 20 '08 #4
acoder
16,027 Recognized Expert Moderator MVP
Not just Internet Explorer - every browser (or at least every major one) has a confirm() method.

Instead of onunload, you'd have to use onbeforeunload though because once it gets to the unload event, you can't prevent it. Note that onbeforeunload is not supported in all browsers.

One final point to bear in mind: it is rarely a good idea to have a confirmation when the user clearly wants to leave the page/close the browser.
Sep 20 '08 #5

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

Similar topics

0
3232
by: Vance Kessler | last post by:
Yes, yes, I know why are we using Crystal 7 under Windows 2003. Well we have to for now. We had a website that was working just fine under Windows 2000 then we re-staged the boxes upgraded to Windows 2003 and now we are having problems with Crystal 7. The thing is that this works on development machines also running the same version of Windows 2003. We are not running in IIS 5 compatibility mode nor do we want to. The problem is...
38
5729
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I find an answer to this question (don't find it in the W3C_char_entities document). -- Haines Brown brownh@hartford-hwp.com
13
3074
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled across "null" string. I know that I will get an "undefined" when I try to retrieve something from the DOM which doesn't exist. I have used null myself to initialize or reset variables. But in which
22
130150
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the document and closes it with the following code: <body onload="window.print(); window.close();"> This works correctly (or at least the way I expect it to work under MS Internet Explorer, but it cuases Netscape to "crash"
15
8584
by: cj | last post by:
How can I get a button in VB to send the contents of a text box via email in a manner similar to the "Send To\Mail Recipient" functionality that you can select via right clicking a file in Windows Explorer? I want the user to click a button and it lunch the users default email client and put the contents of a multi line text box in the body of the message and the contents of another text box in the title box and be sitting there read for...
5
28239
by: balakrishnan.dinesh | last post by:
hi Frnds, I need Confirm box with "yes" or "no" buttons, Is that possible in JAVASCRIPT , Can anyone tell me the solution for this or anyother way to create confirm box with "yes" or "no" button? Thanks & Rgrds Dinesh...
12
2331
by: Pao | last post by:
Hi all For all NEW sites (virtual directories) that I create, I receive always the same error: (I translate so may be a little different) Impossible to visualize the XML page Impossible to visualize the XML input through the XSL sheet. Correct the error, then click on Update, or try another time.
8
5073
jmoudy77
by: jmoudy77 | last post by:
Hi, I've got a form that allows a user to imput their flight data. I programmed a MsgBox into the save button that asks if the user wants to input another duty position for the flight. If no, the record saves and the formresets for the next rocord input. If yes, the record is saved and the duty position and mode of flight fields are set to null, with the remainder of the fields retaining the data already entered. The problem is that...
7
4834
by: EManning | last post by:
Using A2003. I'm receiving this error when returning from a "DoCmd.OpenReport..." statement. I have a tab control with a subform on every tab. The user selects an item from a combobox at the top of the main form which refreshes all the subforms. If this DoCmd statement is not executed, then I don't receive the error. I tried a "DoCmd.OpenQuery..." instead of a report but get the same error. I want the user to be able to...
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8589
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1591
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.