Detect Close Browser

G

Guest

Hi misters, I have an aplication web asp.net 2.0 and I am Trying to detect
the close event in browser, which is the best performance for do this ?

What's up with Alt+F4, Refresh, user clicks X, etc ?

Thanks.
 
M

Mark Rae

Hi misters,
LOL!

I have an aplication web asp.net 2.0 and I am Trying to detect
the close event in browser

You can't...
What's up with Alt+F4, user clicks X, etc ?

Nothing is up with with them - they perform the same function in a web
browser application as in any other Windows desktop application...
 
M

Mark Rae

See if Response.IsClientConnected property can help you.

I'm really curious to know how you think this could possibly detect that the
user has closed the browser after the HttpResponse has been streamed down to
the client...
http://www.devx.com/vb2themax/Tip/18495
http://www.thescripts.com/forum/thread492832.html

1) Client sends request to webserver
2) Webserver processes request
3) Webserver sends response to client
4) Client closes browser / navigates to another site

There simply is no way for the webserver to know that 4) has happened...
 
G

Guest

And using onbeforeunload ??

<script language=JavaScript>
<!--
function window::eek:nbeforeunload()
{
if ( window.event.clientY < 0 )
{
// User closed the browser via the 'X' button;

window.event.returnValue =
'You are closing the application without saving the current transaction.';
}
}
// -->
</script>

any solution using cookies ??


Thanks in advance
 
A

Aidy

I don't. But there are scenarios where this property can be useful.

It is only useful if you are streaming a lot of data and want to check that
the client is still connected and receiving the data. If not you can
terminate your code and save some resources. Once the page has downloaded
the client is always disconnected as HTTP is a connectionless protocol.
 
A

Aidy

And using onbeforeunload ??

That also fires if they navigate away, not just close the browser.
 
M

Mark Rae

That also fires if they navigate away, not just close the browser.

Not only that, it will fire while the user moves from page to page within
the same site...
 
M

Mark Rae

And using onbeforeunload ??
<script language=JavaScript>

Stop - think - take a step back...

What you have written is a client-side JavaScript function - how can the
server ever possibly know about it...???
any solution using cookies ??

Same answer - the server can only detect the presence of cookies when it
receives an HttpRequest from a client browser...
 
M

Mark Rae

It is only useful if you are streaming a lot of data and want to check
that the client is still connected and receiving the data. If not you can
terminate your code and save some resources. Once the page has downloaded
the client is always disconnected as HTTP is a connectionless protocol.

Yes indeed...
 
E

Eliyahu Goldin

I'm really curious to know how you think this could possibly detect that
the
user has closed the browser after the HttpResponse has been streamed down to
the client...
I don't. But there are scenarios where this property can be useful. All I am
saying is that the OP can check whether these scenarios are relevant for
him.
 

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,582
Members
45,061
Latest member
KetonaraKeto

Latest Threads

Top