Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-03-2012, 03:21 PM   PM User | #1
Clawed
New Coder

 
Join Date: Nov 2012
Location: United Kingdom
Posts: 29
Thanks: 3
Thanked 0 Times in 0 Posts
Clawed is an unknown quantity at this point
Session timer & idle timer

Hi,

Like i said in this thread: http://www.codingforums.com/showthread.php?t=283412

I'm building a CMS with session timer and idle timer and i was wondering if it's anything to do with jQuery or JS?!?!?!?

Much help would be appreciated.
Thanks.
Clawed is offline   Reply With Quote
Old 12-03-2012, 04:31 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This script will redirect if no mouse movement has been detected after x seconds, but bear in mind it only works if Javascript is enabled in the browser.

Code:
<html>
<head>

<script type = "text/javascript">

var timeInSecs;
var ticker;
var tim;

function check() {
clearInterval(ticker);
clearInterval(tim);
startTimer(6);  // start or re-start the timer - 6 seconds - change to 60 for one minute, 3600 for 60 minutes
}

function startTimer(secs){
document.getElementById("message").innerHTML="";
timeInSecs = parseInt(secs);
ticker = setInterval("tick()",1000); 
}

function tick() {
var secs = timeInSecs;
document.getElementById("countdown").innerHTML = secs;  // REMOVE AFTER TESTING
if (secs>0) {
timeInSecs--;
}
else {
clearInterval(ticker); // stop counting at zero
document.getElementById("message").innerHTML="Unless you move your mouse within 60 seconds you will be disconnected";
tim = window.setTimeout("disconnect()", 6000);  // 6 seconds - change to 60000 for 60 seconds
}
}

function disconnect() {
window.location = "http://www.google.com";
}


</script>
</head>

<body onmousemove = "check()">

<div id = "countdown"></div><br>
<!-- 
Remove countdown div after testing unless you wish to show this.
 -->
<div id = "message" style = "font-size:18pt;font-weight:bold;text-align:center;color:red;";></div>


</body>
</html>

"If you think education is expensive, try ignorance." - Derek Bok (1930-), Harvard University President
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:57 PM.


Advertisement
Log in to turn off these ads.