After working on this inherited code for some time, I've managed to get it functioning properly during the first countdown session. However, I suspect that there may be multiple timers running after a session refresh. I believe I need to use clearInterval() to ensure a stable 20-minute timer, but I'm unsure of the correct way to implement it. Any assistance would be greatly appreciated.
<script type="text/javascript">
var DoLogout = 1;
var WarnMills;
var TimeoutMills;
var WarnDurationMills;
var RedirectURL;
var _timeLeft;
function StartTimeout(TimeoutValue, WarnValue, WarnDuration, URLValue) {
TimeoutMills = TimeoutValue;
WarnMills = WarnValue;
WarnDurationMills = WarnDuration;
RedirectURL = URLValue;
setTimeout(UserTimeout, TimeoutMills);
setTimeout(WarnTimeout, WarnMills);
}
function UserTimeout() {
if (DoLogout == 1) {
top.location.href = RedirectURL;
}
else {
DoLogout = 1;
setTimeout(UserTimeout, TimeoutMills);
setTimeout(WarnTimeout, WarnMills);
}
}
function WarnTimeout() {
_timeLeft = (WarnDurationMills / 1000);
updateCountDown();
$find('mdlSessionTimeout').show();
}
function updateCountDown() {
var min = Math.floor(_timeLeft / 60);
var sec = _timeLeft % 60;
if (sec < 10)
sec = "0" + sec;
document.getElementById("CountDownHolder").innerHTML = min + ":" + sec;
if (_timeLeft > 0) {
_timeLeft--;
setTimeout(updateCountDown, 1000);
}
else {
window.location.replace("AdminLogin.aspx");
}
if (_timeLeft < (5 * 60)) {
$find('mdlSessionTimeout').show();
}
}
function PreserveSession() {
{
$.ajax({
type: "POST",
url: "SessionKeepAlive.asmx/Check",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
cache: false,
success: checkAuthenticatedOk,
error: checkAuthenticatedError
});
}
}
function checkAuthenticatedOk() {
DoLogout = 0;
_timeLeft = (20 * 60);
TimeoutMills = (20 * 60 * 1000);
$find('mdlSessionTimeout').hide();
}
function checkAuthenticatedError() {
window.location.replace("AdminLogin.aspx");
}