I have a little problem regarding browser window closing,
Basically, I have a page which I want to close after 15 minutes of inactivity. I alraeady managed to make a timer that will alert the window after inactivity for 10 minutes.
What I need is that on timer finish, a popup/alert with a visible countdown comes up and from here the user can either continue with his session or end it. If the user does not click on continue or ignore the popup for 5 more minutes, both the popup and parent window will close. Else if the user presses continue the popup will close and the main page is refreshed (and thus starting the timer again) Any suggestions? Here is my code:
var idleTime = 0;
var activeTime = 0;
var warningFlag = 0;
var loginTime = new Date();
var logoutTime = loginTime;
setInterval(function checkIdle() {
idleTime += 1;
activeTime += 1;
if(idleTime > 10) {
alert("You've been inactive for 10 \n minutes, are you still there ?\nYou logged in at " + loginTime);
warningFlag=1;
}
if((idleTime > 15) && (warningFlag==1)) {
alert("You've been logged out due to inactivity for 15 \n minutes? \nYou logged out at " + logoutTime);
window.close();
}
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
},1000);
function resetTimer() {
idleTime = 0;
}
Instead of alert window use a div for that visibility hidden/visible is toggled. That div should contain another container, div or span, for displaying the countdown time.