Click to See Complete Forum and Search --> : When user click on the close window, Confirm window should open


arthivb
January 22nd, 2005, 01:27 AM
Javascript - Close Window


I need some aids here. When user click on the close window, I want a pop up button asking user if he wishes to logout. How can I do that? Can someone point me where to go from here?

If the user clicks Yes I want reload the Page load event in asp.net..

Thanks,
Arthi

Dr. Script
January 27th, 2005, 06:49 PM
Well ... it would require the use of the onunload event, which as far as I know, lacks support in several browsers. I would avoid using this event, since it would require you to reopen the window.

Dr. Script

Dia
January 28th, 2005, 04:00 AM
Hi,

You could simply use JavaScript's built-in function "confirm" for this....

<input type="submit" value="Close Window" onclick="return confirm('Do you want to logout?');">

What would happen with above code is that when you click the "Close Window" button, you will get a dialog box asking you to confirm logging out which will have 2 buttons "OK" and "Cancel". If you press Ok, then whatever the action on Submit is specified will take place otherwise confirm will return false and nothing will happen.

If you want that something else must happen on "Cancel" as well, then you will have to capture the value returned by confirm() and use if-else for further processing....

Take care & Allah Hafiz
~Dia

Dr. Script
January 28th, 2005, 04:32 PM
Yes, that will work. I took the question to mean close by utilizing the X. That provided code is probably your best option.