I am exploring a potential in-house content delivery system where we have to keep track of student time-on-task. As long as the student is interacting with the page, there is no problem. If the student goes out for lunch leaving the page open, the session should time-out and they will not get credit for their on-line time after the timeout.
I already figure I can easily capture events like navigating away from a page and recording that fact with PHP into the student's record in MySQL, but what is the best way to time a student out? JavaScript? I looked around and haven't found a good explanation yet.
Thanks for any help!
---------- EDIT --------------
After Floris' suggestion about looking at a particular post about idleness, most suggested a JQuery solution, but one poster had a simple solution with no JQuery. Does this code seem like it will work? It looks fine to me:
var inactivityTime = function () {
var t;
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
function logout() {
alert("You are now logged out.")
//location.href = 'logout.php'
}
function resetTimer() {
clearTimeout(t);
t = setTimeout(logout, 3000)
// 1000 milisec = 1 sec
}
};