Detect Close Browser

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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...
 
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...
 
And using onbeforeunload ??

<script language=JavaScript>
<!--
function window::onbeforeunload()
{
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
 
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.
 
And using onbeforeunload ??

That also fires if they navigate away, not just close the browser.
 
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...
 
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...
 
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.
 
Back
Top