I have this code to do this task: if no activity from user (mousemove and keypress) for 10 seconds then display a dialog (Jquery UI dialog) to warn and let user know they will be redirected to another page in the next 5 seconds unless they do something. How do I make the "5" in "You will be automatically redirected to ... after 5 seconds." to be counting down as 5, 4, 3, 2, 1 => then redirect ?
<script>
// Set timeout variables.
var timoutWarning = 10000; // Display warning in 10 seconds.
var timoutNow = 15000; // Timeout in 15 seconds
var logoutUrl = 'http://google.com'; // URL to redirect to.
var warningTimer;
var timeoutTimer;
// Start timers.
function StartTimers() {
warningTimer = setTimeout("IdleWarning()", timoutWarning);
timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
}
// Reset timers.
function ResetTimers() {
clearTimeout(warningTimer);
clearTimeout(timeoutTimer);
StartTimers();
$("#timeout").dialog('close');
}
// Show idle timeout warning dialog.
function IdleWarning() {
$("#timeout").dialog({
modal: true
});
}
// redirect the user.
function IdleTimeout() {
window.location = logoutUrl;
}
</script>
html
<style>
#timeout {
display: none;
}
</style>
<body onload="StartTimers();" onmousemove="ResetTimers();" onclick="ResetTimers();">
<form id="form1" runat="server" defaultbutton="DoNothing">
<asp:Button ID="DoNothing" runat="server" Enabled="false" Style="display: none;" />
<div class="page-container">
<div class="container">
Hold your mouse and don't press any key for 10 seconds, an dialog alert will be displayed.
<div id="timeout">
<h1>Session About To Timeout</h1>
<p>
You will be automatically redirected to google after 5 seconds.<br />
To stay on this page move your mouse or press any key.
</p>
</div>
</div>
</div>
</form>