/    Sign up×
Community /Pin to ProfileBookmark

Onunload solution required

Hi All

I have a website that uses a database that is also being accessed by in-house personnel over a network.

On the website when a user logs in I set intstatus in the database to 1 so that internal personnel can see that the account is currently being updated on the web and when the user clicks on the logout link I set intstatus back to 0.

My problem is how to set intstatus to 0 if the user either closes their browser or browses to a different web page, I thought of using a simple onunload event that redirects to a page that sets intstatus to 0 and then closes itself however this fails because the onunload event triggers even when the user clicks on a link to another page within the website.

To summarise I’m really looking for a way to activate a script if the user a) closes their broswer or b) goes to an external website.

Any help at all greatly appreciated.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Apr 04.2006 — look into onbeforeunload

You really need to use a server side solution with session end since you can not rely on the client.

Eric
Copy linkTweet thisAlerts:
@fvillenaauthorApr 04.2006 — Thanks Eric

I agree a serever side solution may be required but now that I've started looking into this I'd be interested to get a javascript solution.

According to [URL]http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/events/onbeforeunload.asp[/URL] onbeforeunload like on unload will kick in when the user goes to another web page or submits a form etc.
Copy linkTweet thisAlerts:
@felgallApr 04.2006 — Only in browsers with Javascript enabled and which understand the non-standard onbeforeunload event.

onunload will work in lots more browsers than onbeforeunload because it is a standard event however it only has time to run one or two Javascript commands before the page closes.
Copy linkTweet thisAlerts:
@fvillenaauthorApr 05.2006 — Hi Stephen

I would have no problem with using onunload if I could find a way to only execute the script if the user either closes the browser or navigates to a page outwith my own website.

Anybody got any ideas?
Copy linkTweet thisAlerts:
@VladdyApr 05.2006 — Trying to rely on the client will only cause you headaches:

- what if someone loses power

- what if the browser crashes

Just implement server side session timeout - one simple solution for all contingencies.
Copy linkTweet thisAlerts:
@felgallApr 05.2006 — Server side session timeout is the way all of the major web sites handle it because it is the only way that is reliable.
×

Success!

Help @fvillena 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.17,
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,
)...