You’ve already done it in the code above for the resetIdleTimeout function. You just need to do it for a showWarning function, and then in there do it again for the resetIdleTimeout function.
No not really. Having two timers going at the same time introduces more problems.
It is harder to break the simpler situation, where only one timer is used at a time.
First one timer for the warning message. And then, when the warning is shown, to start another timer for 1 minute to redirect.
Thank you for your input. Is your code a stand alone code or an addition to my existing first posted code? I can’t seem to get it to work either way.
So here is the code so far. Have the times short for easier testing. The alert comes up but the rest fails. I assume that if you click ok on the alert, the time should start over and if not it should redirect? Thank you for your help.
<script type="text/javascript">
(function () {
var idleDurationSecs = 7000;
var redirectUrl = 'timeranout.htm'; // Redirect idle users to this URL
var idleTimeout;
setTimeout(function () { alert("Hello"); }, 5000);
var resetIdleTimeout = function () {
if (idleTimeout) clearTimeout(idleTimeout);
idleTimeout = setTimeout(function () {
location.href = redirectUrl
}, idleDurationSecs * 1000);
};
resetIdleTimeout();
['click', 'touchstart', 'mousemove'].forEach(function (evt) {
document.addEventListener(evt, resetIdleTimeout, false)
});
})();
</script>