Creative Juices Bo. Co.

Satisfy Your Thirst For Something Refreshing!

CJ Session Timer 2.0

A Javascript Session Time-Out Timer

I was running into a little problem with a website of mine that was experiencing some weird errors. The site has a password protected directory that allows the users to edit upcoming events. The problem was that this site was on a shared hosting environment and I didn't have control over the session timeout length. They had it set at 30 minutes and it sometimes took people longer than this to complete their edit (or maybe they took a phone call). When they tried to enter the event, they would get redirected to an error page without really knowing why.

I decided to make a simple little javascript timer that would alert the user that the session had expired and then send them to the logout script automatically. This isn't the most graceful way of handling this, because they still loose whatever data they were trying to enter, but at least now they know they have a limited amount of time to make their updates.

The script is fairly straightforward. You will need to change the "redirect" path to point to your ColdFusion (or whatever server language you are using) logout script.

To invoke the script, just place this line within the <head> section of your web page. (Please note, you will also need to load jQuery before loading this script)

<script src="jquery.cj.session_timeout.js" type="text/javascript"></script>

You can then initialize the like so:

$("#myDiv").cjSessionTimeout({
     redirect: "logout.cfm",
     delay: 25,
     message: "Session has timed out!"
});

The redirect is the URL that will be called once the timer has run to zero. Delay is the number of minutes to set your timer for. Message is the message displayed to the user once the timer completes.

So far this has been tested with jQuery 1.3 and 1.4. Any questions or problems, let me know.