i have a javascript function that counts down time from 1 minut to zero and when time arrives to zero the user redirect to a php page by ajax object and in that destination page session destroys and user becomes logout.following is the js function that works corectly:
let minute=1;
let second=0;
function showTimer(){
let minuteString="";
let secondString="";
if(second==0){
second=60;
}
if(second == 59){
minute--;
}
if(minute < 10){
minuteString="0"+minute;
}else{
minuteString=minute;
}
if(second < 10){
secondString="0"+second;
}else if(second==60){
secondString="00";
}else{
secondString=second;
}
document.getElementById("timerContainer").innerHTML = secondString+" :
"+minuteString;
second --;
if(minute==0 && second==0){ //if the time becomes expire
//step1:
let request = new XMLHttpRequest;
//step2:
request.open("GET", "../model/header.php?expire=true");
//step3:
request.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
window.location.replace("../index.php");
}
};
//step4:
request.send();
}
setTimeout(showTimer, 1000);
}
but i need to reset primary time if the user gets any action in page(scroll, click, rightclick, keypress, touch, move the mouse...) but if he doesn't do any thing in page my function should counting the time down to the zero and then takes the user logout. you know it isn't possible that i define all of js events in page. I want a javascript method or function or any other solution to detect every user actions in the page. could you help me??