The front-end js is used as a monitor. If there is neither mouse operation nor keyboard operation for a long time (for example: 30 minutes), a box will pop up to remind the user.
Correction:
What I gave before was pseudo-code, which was only meaningful and not guaranteed to be correct, but the questioner obviously took it seriously, so I had no choice but to change it a little bit, at least it can run
For example:
var timer;
var setTimer = function(){
timer = setTimeout(function() {
alert('你大爷的,也不动一动?');
setTimer();
}, 5000);
};
setTimer();
var handler = function(){
clearTimeout(timer);
setTimer();
};
document.addEventListener('keyup', handler, false);
document.addEventListener('mousemove', handler, false);
Is it more appropriate to do it on the front end?
The front-end js is used as a monitor. If there is neither mouse operation nor keyboard operation for a long time (for example: 30 minutes), a box will pop up to remind the user.
Correction:
What I gave before was pseudo-code, which was only meaningful and not guaranteed to be correct, but the questioner obviously took it seriously, so I had no choice but to change it a little bit, at least it can run
For example: