473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to detect browser close

Sat. Oct. 30, 2004 3:25 PM PT

I want to detect, if user has close the browser, (after logging to my site),
that user has closed the browser. How to achieve it ? I want to know this
close action on my server-side code. Because if he logout by clicking on
Logout/ Sign-Off button it simple to get the message.

Although, this is very similar to the first above. Also, if user takes any
action on client-side or browser side how will I detect or send a message to
server-side that user has taken xyzAction ?

Thanks in Advance.

Nov 18 '05 #1
3 4244
Point is that there is no 100% way to guarantee that. You can try having js
scripts to send something to the server when browser gets closed or
something else happens, but if user has disabled js, you are out of luck.
You should design the app such that occasions like this are taken into
account, you just can't help it.
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke


"Lord2702" <Lo******@MSN.com> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
Sat. Oct. 30, 2004 3:25 PM PT

I want to detect, if user has close the browser, (after logging to my site), that user has closed the browser. How to achieve it ? I want to know this
close action on my server-side code. Because if he logout by clicking on
Logout/ Sign-Off button it simple to get the message.

Although, this is very similar to the first above. Also, if user takes any
action on client-side or browser side how will I detect or send a message to server-side that user has taken xyzAction ?

Thanks in Advance.

Nov 18 '05 #2
You should only respond on the session timing out, or the button being
clicked - other than that assume that your client is still connected.

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP

"Lord2702" <Lo******@MSN.com> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
Sat. Oct. 30, 2004 3:25 PM PT

I want to detect, if user has close the browser, (after logging to my site), that user has closed the browser. How to achieve it ? I want to know this
close action on my server-side code. Because if he logout by clicking on
Logout/ Sign-Off button it simple to get the message.

Although, this is very similar to the first above. Also, if user takes any
action on client-side or browser side how will I detect or send a message to server-side that user has taken xyzAction ?

Thanks in Advance.

Nov 18 '05 #3
Hi,

As others have said this is a tricky issue. The odds of you getting a
succesful postback are 50/50 to say the best. I've had about a 95% success
rate doing this:

1. Capture the onbeforeunload event in your body tag.
2. Incorporate the WebService.htc.
3. When the onbeforeunload event fires run a function that uses the
WebService.htc to tell a web service.

The browser will close before you get a response back but, about 95% of the
time, your web service will get hit and the user can successfully be logged
out. Note, that using the latest IE and Windows XP you will achieve almost
100% results. This is sort of complicated until you get the hang of it. If
this isn't something you want to try then here is another suggestion to
improve your chances but it might seem clunky to the user:

Have a main page that the user browses to. To run your app, they click a
button or link and then you use window.open() to create a new browser
window. This is the window your app runs from. Don't ask me why, but the
success rate of a postback from onbeforeunload seems to be much higher for
browsers launched from javascript than from browsers launched by the user.
Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Lord2702" <Lo******@MSN.com> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
Sat. Oct. 30, 2004 3:25 PM PT

I want to detect, if user has close the browser, (after logging to my site), that user has closed the browser. How to achieve it ? I want to know this
close action on my server-side code. Because if he logout by clicking on
Logout/ Sign-Off button it simple to get the message.

Although, this is very similar to the first above. Also, if user takes any
action on client-side or browser side how will I detect or send a message to server-side that user has taken xyzAction ?

Thanks in Advance.

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hb | last post by:
Hi, Would you please tell me how to detect if the client's browser is closed? I need such event to trigger a database modification. Thank you hb
2
by: NWx | last post by:
Hi, I have the following question: I have an app that uses user login/logout to identify users When user logon, I register logon time in a session variable When user logoff using the logout...
3
by: Lord2702 | last post by:
Fri. Oct. 08, 2004 11:10 PM PT In ASP.NET application, How to detect that user has close the browser, IE or Netscape, or may be any other ? Thanks,
8
by: Luke Matuszewski | last post by:
I have read all posts about how to detect that url have changed to new page and trigger the event handler then eg. function aidLogout(evt) { if(evt) { /* maybe via analyse of evt object i can...
1
by: bloodandrose | last post by:
Can you help me How to detect browser close event? Thanks
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
1
by: mark4asp | last post by:
<!-- // How to detect the rendering mode which the browser is currently in (works for IE6). // Ctrl+Shift+s displays indicates whether the browser is in quirks or standards mode. // Detect...
11
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
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,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.