View Full Version : Disable the X button of browser window

02-04-2003, 08:50 PM
Can anyone please let me know as to how to disable the close(X) button of your browser window?

I am developing an application in which when a user clicks on a logout button, his logout time is recorded. But for this I should not allow him to instead click the close window button.

So how do I go about this.

02-04-2003, 09:36 PM
You can't do that, you will have to look for another solution. There are many posts here regarding logout times, however in classic ASP this is unreliable.

02-05-2003, 01:27 AM
...and here is a long thread about this:

02-05-2003, 01:31 PM
I had a similar problem. Our solution was to use javascript to detect when the user was leaving the site and automatically log them out (there are many scripts available to detect this, but it creates a lot of work for the webmaster). It was "preferred" rather than "vital" that people logged out and the site only worked for people who had javascript enabled anyways, so it was a perfect solution for us.

02-05-2003, 11:59 PM
Like I was saying it is unreliable in a web application (at least with classic ASP), and really the reasoning behind why is simple:

Since these are server-side applications, you have no way to know if the user has closed the browser, since no request is then sent to the server.

You can use onunload (or IE's onbeforeunload), but they are not very reliable either.

...as a matter of fact my ASP.NET books talk about this exact subject...

The only solutions I've seen rely on the application and session objects to set a false logout time when the session automatically expires, or someone else (the next user, for instance) updates an application variable...

02-06-2003, 08:53 AM
I guess you could launch the application in a window with no borders or other paraphernalia, such as used by some advertisers. You'd need to check javascript sites to work out how this is done.

02-06-2003, 09:25 AM
even if there is no X button, you could still close the window by hitting Alt+F4 :D
if you look at the solution I suggested in the thread I posted, you can detect if the user clicks X or Alt+F4.
This may not be a complete solution, but still worth trying :)