简体   繁体   English

用户闲置而不在Firefox浏览器上工作时引发事件

[英]Fire Event When User is Idle, Not Working on Firefox Browser

I have this code for checking if user is active or not in page. 我有此代码来检查用户是否在页面中处于活动状态。 But not working on Firefox once you leave your cursor in page. 但是,一旦将光标留在页面上,就不能在Firefox上使用。 It seems the mouseover still triggered. 似乎鼠标悬停仍在触发。 But perfectly working on Chrome. 但可以在Chrome上完美运行。

idleTimer = null;
idleState = false;
idleWait = 2000;

(function ($) {
  $(document).ready(function () {
    $('*').bind('mousemove keydown scroll', function () {        
        clearTimeout(idleTimer);                    
        if (idleState == true) {                 
            // Reactivated event
            $("body").append("<p>Welcome Back.</p>");            
        }

        idleState = false;            
        idleTimer = setTimeout(function () {                 
            // Idle Event
            $("body").append("<p>You've been idle for " + idleWait/1000 + " seconds.</p>");
            idleState = true; }, idleWait);
        });

    $("body").trigger("mousemove");    
  });
}) (jQuery)

Following this tutorial link: https://css-tricks.com/snippets/jquery/fire-event-when-user-is-idle/ 遵循本教程链接: https : //css-tricks.com/snippets/jquery/fire-event-when-user-is-idle/

Please help on how to fix this on Firefox Browser. 请提供有关如何在Firefox浏览器上解决此问题的帮助。 Thank you :) 谢谢 :)

SOLVED I'm doing it with Ruby on Rails. 解决了,我正在用Ruby on Rails做到这一点。 I put the file in assets/javascripts directory. 我将文件放在assets / javascripts目录中。 Finally solved it by adding it to required js in application.js like: 最后通过将其添加到application.js中的必需js中来解决它,例如:

//= require js_file

And, important to removed the jquery document function, because it will cause the same error in Firefox. 并且,重要的是删除jquery文档功能,因为它将在Firefox中引起相同的错误。 Add ONLY the main js code to file, it will be loaded automatically.: 仅将主要js代码添加到文件中,它将自动加载。

Important to Remove: (function ($) {}); 要删除的重要信息:(函数($){}); $(document).ready(function () {}); $(document).ready(function(){});

And, at the bottom of code, add like: 并且,在代码底部,添加如下内容:

$(document).ready(ready);
$(document).on("page:load", ready);

Now, both Chrome and Firefox works well. 现在,Chrome和Firefox都可以正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM