473,503 Members | 1,700 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 9511
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
3223
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...
38
5695
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...
13
3063
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...
22
129953
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...
15
8562
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...
5
28230
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?...
12
2314
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...
8
5062
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...
7
4822
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...
0
7202
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
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7278
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
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7458
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...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
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...
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
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...

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.