/    Sign up×
Community /Pin to ProfileBookmark

To find out if user’s going to leave the site

Please help!

Is it possible to find out if the user’s going to leave my site either by closing browser or going to another site?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@7studFeb 03.2005 — Yes. What are you trying to do?
Copy linkTweet thisAlerts:
@Andrey222authorFeb 03.2005 — I need to logout user if he leave the site in any way
Copy linkTweet thisAlerts:
@CharlesFeb 03.2005 — [i]Originally posted by Andrey222 [/i]

[B]I need to logout user if he leave the site in any way [/B][/QUOTE]
They you are SOL. You'll need to keep track of the time on the site and log them out when they've been inactive for a few hours.

If you don't need this information, but it would be nice to have you could do something with JavaScript. But JavaScript doesn't work for all users.

The trick is to use the JavaScript "onunload" handler to cache an image. Only instead of an image, we call your CGI script:

[font=monospace]<script type="text/javascript">

onunload = function () {

var cache = new Image();

cache.src = 'http://www.mysite.com/log-off.pl';

}

</script>[/font]
×

Success!

Help @Andrey222 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...