【问题标题】:Script to find the page idle time查找页面空闲时间的脚本
【发布时间】:2012-07-26 06:44:20
【问题描述】:

如果用户没有在页面上执行任何任务,即页面处于空闲状态,是否有任何方法可以捕获页面空闲或没有执行任何操作的时间。我在我的项目中使用了 JSP、struts1、JQM、JS。

【问题讨论】:

  • 你所说的“在上面做某事”是什么意思?
  • 一个页面是基于事件的,一些动作会触发一个事件。你是说如果没有“事件”你想记录“时间”。还是说没有“服务器端”回发?

标签: javascript jquery ajax jsp jquery-mobile


【解决方案1】:

空闲时间实现使用:

  1. YUI
  2. jQuery
  3. 或者使用下面的脚本:

    <script type="text/javascript">
    idleTime = 0;
    
    $(document).ready(function () {
        //Increment the idle time counter every minute.
        var idleInterval = setInterval("timerIncrement()", 60000); // 1 minute
    
        //Zero the idle timer on mouse movement.
        $(this).mousemove(function (e) {
            idleTime = 0;
        });
    
        $(this).keypress(function (e) {
            idleTime = 0;
        });
    })
    
    function timerIncrement() {
        idleTime = idleTime + 1;
    
        if (idleTime > 19) { // 20 minutes
            window.location.reload();
        }
    }
    </script>
    

【讨论】:

【解决方案2】:

您可以使用 body-tag 的 Triggers onclick、onmousemove 和 onkeypress 来获取当前用户操作。在其中一个触发后,您可以设置时间戳并通过 setTimeout() 或 setIntervall() 查询空闲时间。您获取当前时间戳并从最后一个操作中减去时间戳。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多