Hi everyone, I am looking to get some help creating something that would force a new login if a timer in javascript has expired.
Here is what have so far this is just the timer displayed for the user warning them that the session will expire in so much time.
I now need to make it that if the timer gets to 0 then it would redirect to my login page and force them to login again.
Here is what have so far this is just the timer displayed for the user warning them that the session will expire in so much time.
I now need to make it that if the timer gets to 0 then it would redirect to my login page and force them to login again.
Code:
function startTimer(duration, display) { var start = Date.now(), diff, minutes, seconds; function timer() { // get the number of seconds that have elapsed since // startTimer() was called diff = duration - (((Date.now() - start) / 1000) | 0); // does the same job as parseInt truncates the float minutes = (diff / 60) | 0; seconds = (diff % 60) | 0; minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; display.textContent = minutes + ":" + seconds; if (diff <= 0) { // add one second so that the count down starts at the full duration // example 05:00 not 04:59 start = Date.now() + 1000; } }; // we don't want to wait a full second before the timer starts timer(); setInterval(timer, 1000); } window.onload = function () { var fiveMinutes = 60 * 180, display = document.querySelector('#time'); startTimer(fiveMinutes, display); };
HTML Code:
<div align=center><font face="GE Inspira"><strong>Session closes in <span id="time"></span> minutes!</strong></font></div>
Comment