473,385 Members | 1,769 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,385 software developers and data experts.

How do I detect a user leaving the site?

As per the question really.

Not trying to stop them leaving, but just detect WHEN they leave the site

Jun 27 '08 #1
5 2901
Due to disconnected nature of the Web applications it's a bit hard (and
always not reliable).

First you need to define for yourself "exit time".
Then you need to define precision. For example "We need 1 hour timeframe".
Meaning that if user left 8:50 and we detected it by 9:00 then we fine... .
-------------------------------------------------
Here are some thing you can test if they going to work for you.

1. You can get last time user has requested anything from your site. And
call it your "exit time". Basically update exit time everytime user had send
a request to aspx. At the end when user closes the browser you will have
last "exit time".

Problem: if user requested page "article.aspx" and then sitting there
reading it for 30 minutes and then closes browser you will have exit time 30
minutes before user actually closed the browser...

But this comes does to definition of what is "exit time".

2. To reduce lag time specified in #1 you can have a JavaScript that would
refresh a tiny image on your page every minute. then if user looked at your
page for 30 minutes you will have exit time within one minute range...

But this comes down to the precision... And obviously will have a problem if
JavaScript is disabled.

Check out this on how to do that with an image...
http://www.codeproject.com/KB/aspnet...onForever.aspx
----------------------------------------------------

George.
"Andy" <An**@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
As per the question really.

Not trying to stop them leaving, but just detect WHEN they leave the site

Jun 27 '08 #2
You can set up JavaScript on a page, but you will have to make it elaborate
enough to distinguish page unload from page unload to another site. This is
how sites that try to get you to download trojans work, popping up a modal
popup when the user leaves a page, except they do it on any unload.

Storing that they have left will require an AJAX like solution, as you will
have to have the JavaScript contact the server.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"Andy" <An**@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
As per the question really.

Not trying to stop them leaving, but just detect WHEN they leave the site

Jun 27 '08 #3
there is no surefire way. the most common is a lightweight ajax call on page
unload (which will fire on every page referesh), then run a timer on the
server to detect that the user did not return to the site. you can also use a
session timeout for this (20 minutes of no site hits).

-- bruce (sqlwork.com)
"Andy" wrote:
As per the question really.

Not trying to stop them leaving, but just detect WHEN they leave the site
Jun 27 '08 #4
"Andy" <An**@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
Not trying to stop them leaving, but just detect WHEN they leave the site
As per the other replies, there is no 100% reliable way of doing this...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #5
Client side JavaScript is the most surefire, but one can easily circumvent
it by killing the browser. LOL ;-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Andy" <An**@discussions.microsoft.comwrote in message
news:AC**********************************@microsof t.com...
>Not trying to stop them leaving, but just detect WHEN they leave the site

As per the other replies, there is no 100% reliable way of doing this...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #6

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

Similar topics

6
by: gsb | last post by:
I trying to use sessions to save a user name/id after login. If the user leaves the site and comes back, how do I force a new session and login?
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
3
by: someone | last post by:
Hi, Is it possible to detect if the user has shut down the window holding my ASP2.0 page and/or if the user goes to another page? For my application I need the user to click on the EXIT button...
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...
2
by: Cam | last post by:
Hi to all I have searched this subject and found some posts but none of them seem to answer my problem. I am developing a shop site and need to detect when a session times out through...
7
by: hiriumi | last post by:
Hello folks, I have a web application that has basic authentication turned on (IIS). What I would like to accomplish is detect whether user is navigating away from the site or simply going to the...
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",...
7
by: Baron Samedi | last post by:
I coded up a hit counter, then extended it to see who was reading my blog, by matching IP. The problem is that I am swamped by crawlers. How can I detect a human, or a crawler? If I can handle...
18
by: sebastian | last post by:
Can this be done without client-side scripting? I thought sessions might be the answer but after some testing found that sometimes the old session data remained even after the user left the site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.