server needs to know when user closes browser window

  • Thread starter Thread starter feng
  • Start date Start date
F

feng

Hi,

When user closes a browser window by clicking on the "X"
button, I want the server to be noticed (either through
postback or calling other ASP pages, etc.) and perform
some task accordingly. Please note that I can't use
session end event, since the session is still alive now
and the user is just closing a secondary window he/she
opened.

I tried to use the <BODY> tag's onunload client side event
and put a flag in a hidden textbox then submit the form
(post back). But this didn't work for me -- my code on the
server side can't really capture the event properly.

What's the proper way of doing this? Can anyone help me?

Thanks
 
OnUnload is an option, but you have to have a method of speaking to the
server. Perhaps having the code navigate to another page that says "are you
sure you want to close this window" and having that page tell you they are
closing the window. But, that might tick off users.

The difficulty here is HTTP is stateless, which means the client is
disconnected once they have recieved a page. In an Intranet environment, you
have more options, of course.

If you can set up the popup window so there is no header bar (thus no X to
close) and put a "Close window" button, you have the ability to handle the
event on the server side, but this may end up causing a dialog stating
"someone is trying to close this window" or similar.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
Back
Top