Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to detect Windows(X) Close Button?

    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?

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by felgall
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are we talking about an actual window here, or a dialog like confirm() ?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by brothercake
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •