How to detect IE window close (X) action by user?

M

Mark Rae [MVP]

This question comes up time and time again.

Generally speaking, there is no way for the server to know if the client
browser has been closed, or even if the client has navigated to another
website.

This is because of the fundamental architecture of the web.

The server waits for an incoming HttpRequest.

The server processes the incoming HttpRequest.

The server sends back an HttpResponse.

The server waits for an incoming HttpRequest. If no incoming HttpRequest
arrives, there's nothing the server can do about it...

There have been various possible solutions suggested, mainly to do with the
<body onload> method, but none is satisfactory...

Why do you need to know this anyway...?
 
B

bruce barker

in javascript catch the onbeforeunload or onunload event, and check the
event x & y positions (they will be off srceen). its a hack.

-- bruce (sqlwork.com)
 
B

BlueJumper.com

As above, catch the body.unload event and fire a postback event from
Javascript to tell the server the page is closing.

The only draw back is that is will fire when the user closes the
browser and when they move to a different page.


Fran

http://www.bluejumper.com
 
M

Mark Rae [MVP]

As above, catch the body.unload event and fire a postback event from
Javascript to tell the server the page is closing.

The only draw back is that is will fire when the user closes the
browser and when they move to a different page.

That's right - so not much use for any website which has more than one
page...
 
B

BlueJumper.com

That's right - so not much use for any website which has more than one
page...


As you so eloquently pointed out, it depends why you need to do this!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top