By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

Detect if browser closed

P: n/a
Can anybody tell me how to detect is the user has closed the browser

Thank you
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
If this is during a request try IsClientConnected.

Else you have to callback the server when it happens (and in the case of a
client side crash or if JS is disabled etc..., you'll never know the browser
closed).

Generally I try to design for not having to care... (you may want to explain
what you want to do when the user closes the browser).

Patrice

--

"Chris" <cc*********@hotmail.com> a écrit dans le message de
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you

Nov 19 '05 #2

P: n/a
Hi,
If Javascript is enabled in the client side, then you can use window.Closed
property to check whether the window is close.
For eg in Child window to check the parent window is closed you can use
if(window.parent.closed)
// do some thing

Regards,
Sambathraj
"Chris" <cc*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you

Nov 19 '05 #3

P: n/a
Ok what needs to have happen.
when a user edits a record I am locking the record by a bit field.
So if the user clicks the x on that edit screen I need detect that and
unlock the record in the database.

I am storing the locking by user session.sessionID.
If you know of a way to get all session.sessionID's that would work for me
too. I can run a check on that instead. Which is what I want to do.

Thanks

"Chris" <cc*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you

Nov 19 '05 #4

P: n/a
Hi Chris,

You can't tell when the browser has closed, as HTTP is stateless. That is
why Sessions time out, and why there is a Session_End event handler in your
global class. Assuming that your app can wait 20 minutes to perform this
cleanup task, that's the place to do it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Chris" <cc*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok what needs to have happen.
when a user edits a record I am locking the record by a bit field.
So if the user clicks the x on that edit screen I need detect that and
unlock the record in the database.

I am storing the locking by user session.sessionID.
If you know of a way to get all session.sessionID's that would work for me
too. I can run a check on that instead. Which is what I want to do.

Thanks

"Chris" <cc*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you


Nov 19 '05 #5

P: n/a
Are you sure you need exclusive locking ? Did you checked the optimistic
approach ? What is the probability to have multiple people editing the same
record at the same time ?
You could also keep a datetime instead of just a bit field. It would allow
to have a safety mecanism so that a long running lock could be discarded...

If you really need you could trap onbeforeunload or onclose or a similar
client side event to call a server side page to unlock the record.

Patrice

--

"Chris" <cc*********@hotmail.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP10.phx.gbl...
Ok what needs to have happen.
when a user edits a record I am locking the record by a bit field.
So if the user clicks the x on that edit screen I need detect that and
unlock the record in the database.

I am storing the locking by user session.sessionID.
If you know of a way to get all session.sessionID's that would work for me
too. I can run a check on that instead. Which is what I want to do.

Thanks

"Chris" <cc*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you


Nov 19 '05 #6

P: n/a
You may be able to take advantage of the client side OnClose event.
Here's more info:
http://www.mozilla.org/docs/dom/domr...dow_ref56.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Chris" <cc*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you

Nov 19 '05 #7

P: n/a
Well I have gone another route. Just to let you all know.
First off thanks for the info

I am now using the system.web.cacheing.cache
I store a dataset in there with a recordid and a recordtype

now if the user closes his brower it will take about 5 mins for the
application to unlock that record in the cache.
"Chris" <cc*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Can anybody tell me how to detect is the user has closed the browser

Thank you

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.