Javascript timeout when no actions from user for specified time

后端 未结 7 971
广开言路
广开言路 2020-12-28 19:32

I want to call a js function when there is no activity from user on the web page for specified amount of time. If there is activity from user then reset timeout. I tried to

7条回答
  •  孤城傲影
    2020-12-28 20:28

    Also, take a look at jQuery idleTimer plugin from Paul Irish (jquery.idle-timer.js). It was based on Nicholas C. Zakas' Detecting if the user is idle with JavaScript and YUI 3 article (idle-timer.js).

    It looks at similar events to the other answers, plus a few more.

    events  = 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove';
    // activity is one of these events
    

提交回复
热议问题