...

View Full Version : How to detect Windows(X) Close Button?



ivernrawks
06-20-2006, 03:18 AM
How to detect Windows Close Button? I have a popup that has two selections, Agree and Disagree. I want the user to make a choice so he musn't click the X button located at the top right corner of the page. How to return its value?

Spookster
06-20-2006, 03:32 AM
PHP is a server side language which means it runs on the server. You would need a client side language like javascript to detect that.

felgall
06-20-2006, 09:30 PM
Javascript runs in the browser and can only interface with the web page and not the operating system. It can't even tell if the computer is running Windows let alone be able to access the close button. You need something that actually runs on the computer itself and not just in the browser window to be able to detect something like that.

Spookster
06-20-2006, 10:19 PM
Javascript runs in the browser and can only interface with the web page and not the operating system. It can't even tell if the computer is running Windows let alone be able to access the close button. You need something that actually runs on the computer itself and not just in the browser window to be able to detect something like that.

Actually that's not really correct. Javascript interacts with the web browser. The web browser provides information on what operating system you are using as well as much more information which javascript has access to. You can also use javascript to detect when the browser window has been closed. And in their case they want to know if the user closed the window verses choosing one of two options they have provided (Agree/Disagree). That is very definitely possible to do with javascript.

brothercake
06-21-2006, 04:14 AM
Are we talking about an actual window here, or a dialog like confirm() ?

Spookster
06-21-2006, 04:49 AM
Are we talking about an actual window here, or a dialog like confirm() ?


That's a good question. I assumed we were talking about a browser window with with a form with either two push buttons for agree/disagree or a radio button set.

brothercake
06-21-2006, 05:00 AM
Right, well a window is not reliably detectable unless you opened it yourself.

For a popup window to which you have a reference, the "closed" property will return true or false by whether the window is, er, closed - so that could be tested on a timer.

But for a regular window there's only the "unload" event, but that's very sketchy and unreliable.

For a regular dialog like confirm(), the "x" button is programatically the same as pressing "no" or "cancel"

felgall
06-21-2006, 10:08 PM
Javascript only provides access to check the closed property of the window (from another window that has/had access to that window). The window can have been closed lots of different ways and the close button referred to in the original query is just one of them. Javascript can only tell that the window has been closed - not how it was closed. In fact a window can be closed because it was never opened in the first place.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum