普通jQuery中的会话超时

Him*_*dav 4 jquery

如何在不使用任何插件的情况下在普通jQuery中编写sessionTimeOut功能?我想使用我自己的警告ui.要弄清楚我可以写的任何UI活动,但不知道如何在超时功能中将它组合.

$('*').on('click', function () {
    console.log('click', this);

});

$('*').on('change', function() {
    console.log('change', this);
});
Run Code Online (Sandbox Code Playgroud)

A. *_*lff 6

您可以在所有现代浏览器上捕获mousemove事件:

(function () {
    var timeoutSession;
    document.addEventListener('mousemove', function (e) {
        clearTimeout(timeoutSession);
        timeoutSession = setTimeout(function () {
            alert('Make SESSION expire');
            //call a script here to server...
        }, 30000); //30s
    }, true);
})();
Run Code Online (Sandbox Code Playgroud)