I have two pages in an application. The first one does nothing but open the second full-screen with no menu bar, location, toolbar, etc. This second window is my main application window where users log into a system and perform various tasks. The problem I am having is catching when a user clicks the "x" in the top right corner of the browser and closes the browser window. In this situation, I want to log the user out by either redirecting the window to a logout script page (logout.asp) or opening a new window with the logout script page. I've tried all the events of the second application window I could think of, but nothing worked except window.onbeforeunload, which has the problem of firing every time the user refreshes the page. Any help here would be greatly appreciated.