JavaScript function call when page is Idle

Thursday, 5 November 2015

JavaScript:

<script type="text/javascript">
var IDLE_TIMEOUT = 60; // 60 seconds
alert(IDLE_TIMEOUT);
var _idleSecondsCounter = 0;
document.onclick = function() {
    _idleSecondsCounter = 0;
};
document.onmousemove = function() {
    _idleSecondsCounter = 0;
};
document.onkeypress = function() {
    _idleSecondsCounter = 0;
};
window.setInterval(CheckIdleTime, 1000);

function CheckIdleTime() {
    _idleSecondsCounter++;
    var oPanel = document.getElementById("SecondsUntilExpire");
    if (oPanel)
        oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
    if (_idleSecondsCounter >= IDLE_TIMEOUT) {

/*
Your Codes...
This code is call when user view your page and Idle for 60 seconds.
*/
    }
}
</script>

No comments:

Post a Comment

 

Blogger news

Blogroll

Most Reading