I have seen many answers similar to this question.None helped me resolving this. Issue- I want to display a warning message after 5 minutes of inactivity,If the user is still inactive post 5 minutes of warning, Page should automatically redirect to logoff.jsp. I dont want to use Jquery here.It has to be done using Javascript only. Help!!
var IDLE_TIMEOUT = 15; //seconds
var _idleSecondsCounter = 0;
document.onkeypress = function()
{
_idleSecondsCounter = 0;
};
document.onclick = function()
{
_idleSecondsCounter = 0;
};
document.onmousemove = function()
{
_idleSecondsCounter = 0;
};
window.setInterval(CheckIdleTime, 1000);
function CheckIdleTime() {
_idleSecondsCounter++;
var oPanel = document.getElementById("SecondsUntilExpire");
if (oPanel)
oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
var answer = confirm("It's been long time you are idle.\nPlease click OK to continue session.\nTo close this session click Cancel.");
if (answer)
{
//document.location.href = "logout.html";
_idleSecondsCounter=0;
}
else{
//window.open('', '_self', ''); window.close();
document.location.href = "logoff.jsp";
}
}
}