Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 25th, 2003, 05:08 AM
Registered User
Join Date: Jun 2003
Location: Cyberjaya, Selangor, Malaysia.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to detect window Close (X) Button

I need to detect the event when a user click at the window close (X) button. And then, prompt out a confirm box. I'm not sure whether there is a CONSTANT value for the window close (X) button.
Old June 30th, 2003, 08:33 AM
Authorized User
Join Date: Jun 2003
Location: Lexington, KY, USA.
Posts: 46
Thanks: 0
Thanked 1 Time in 1 Post

If you are trying to confirm closing the window, you can do it in IE, but I don't think you can in Netscape (maybe someone else can say).

You can use IE's document.onbeforeunload event, and cancel it. IE then automatically displays a confirmation dialog. If you try to put in your own confirmation dialog, the user will then see two dialogs if they cancel.


But if you mean you want to confirm something else and take some action, you might try the window.onunload event, because that is cross-browser.

(Old dog learning new tricks...)
The Following User Says Thank You to vknowles For This Useful Post:
nanajee (March 4th, 2009)
Old July 27th, 2003, 08:13 PM
Registered User
Join Date: Jul 2003
Location: , , Philippines.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to francis_tudlong


I am implementing an event in which it will show a popup window that contain several questions to answer. This event will only display after i close the browser. But i have a problem. When i refresh tha page it will show the popup window and if i press a link on the page again it will show the popup window. It should only display the popup window if i close the page. How can i implement this in javascript..



Similar Threads
Thread Thread Starter Forum Replies Last Post
window.close() failing to...well...close! mheathcote Javascript How-To 2 October 31st, 2005 03:02 PM
how to detect in asp.net browser window close connect2sandep ASP.NET 1.0 and 1.1 Professional 1 October 31st, 2005 05:01 AM
Close Parent window on opening child window pkdev Javascript How-To 8 April 11th, 2004 12:06 PM
Button to replace close window text Burton HTML Code Clinic 12 November 6th, 2003 12:27 PM
How do i close pop-up window?: window.close () Burton HTML Code Clinic 2 September 8th, 2003 05:40 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.