空闲计时器不工作

发布于 2024-12-20 14:13:46 字数 1204 浏览 1 评论 0原文

我有两个 jQuery 空闲计时器,一个在下面,另一个是类似的代码,其超时值高于第一个。我评论了第二个的超时值。这两个脚本运行在同一个 xhtml 页面上。当第一个模式(超时时间较低的模式)弹出时,我无法关闭它,而且它也不会在“myTimeout”值之后进入重定向页面。

(function($){
            var timer;
            //var timeout = 600000;
            //var myTimeOut = 120000;
            var timeout = 120000;
            var myTimeOut = 60000;
                $(document).bind("idle.idleTimer", function(){
                  $( "#popup-modal" ).dialog({ 
                    modal: true,
                    autoOpen: true,
                    width: 574,
                    resizable : false,
                    draggable:false,
                    open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); $(".ui-dialog-print").hide(); $(".ui-icon").hide(); },
                    show: {effect: 'fade'} 
                    });
                timer = window.setTimeout(function()
                {  window.location.href = "redirectpage.xhtml";},myTimeOut);
                });
            $(document).bind("active.idleTimer", function(){
                timeout = 120000;
               window.clearTimeout(timer);
            });
            $.idleTimer(timeout);
        })(jQuery);

I have two jQuery idle timers one below and the other is similar code with timeout values higher than the first one. I commented timeout values for the second one. The two scripts are running on the same xhtml page. When the first modal(one with lower timeout) pops up, I can't close it and also it doesn't go to the redirect page after the "myTimeout" value.

(function($){
            var timer;
            //var timeout = 600000;
            //var myTimeOut = 120000;
            var timeout = 120000;
            var myTimeOut = 60000;
                $(document).bind("idle.idleTimer", function(){
                  $( "#popup-modal" ).dialog({ 
                    modal: true,
                    autoOpen: true,
                    width: 574,
                    resizable : false,
                    draggable:false,
                    open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); $(".ui-dialog-print").hide(); $(".ui-icon").hide(); },
                    show: {effect: 'fade'} 
                    });
                timer = window.setTimeout(function()
                {  window.location.href = "redirectpage.xhtml";},myTimeOut);
                });
            $(document).bind("active.idleTimer", function(){
                timeout = 120000;
               window.clearTimeout(timer);
            });
            $.idleTimer(timeout);
        })(jQuery);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如何视而不见 2024-12-27 14:13:46

您是否尝试过为对话框的关闭事件添加处理程序?

(function ($) {
    'use strict';
    var timer;
    var timeout = 120000;
    var myTimeOut = 60000;
    //var timeout = 600000;
    //var myTimeOut = 120000;
    function resetRedirectTimer() {
        timeout = 120000;
        window.clearTimeout(timer);
    };
    $(document).bind('idle.idleTimer', function () {
        $("#popup-modal").dialog({
            'modal': true,
            'autoOpen': true,
            'width': 574,
            'resizable': false,
            'draggable': false,
            'close': function (event, ui) {
                resetRedirectTimer();
            },
            'open': function (event, ui) {
                $('.ui-dialog-titlebar-close').hide();
                $('.ui-dialog-print').hide();
                $('.ui-icon').hide();
            },
            'show': {
                'effect': 'fade'
            }
        });
        timer = window.setTimeout(function () {
            window.location.href = 'redirectpage.xhtml';
        }, myTimeOut);
    });
    $(document).bind('active.idleTimer', function () {
        resetRedirectTimer();
    });
    $.idleTimer(timeout);
}(jQuery));

此外,您似乎在打开对话框时隐藏了用于关闭对话框的默认控件。
您还有用于关闭对话框的按钮(或其他控件)吗?

最后,为了澄清问题,您似乎希望在用户处于不活动状态 60 秒后重定向用户,但如果用户再次活动则取消重定向。

这就是你想要实现的目标吗?

希望这有帮助。

皮特

Have you tried adding a handler for the dialog's close event?

(function ($) {
    'use strict';
    var timer;
    var timeout = 120000;
    var myTimeOut = 60000;
    //var timeout = 600000;
    //var myTimeOut = 120000;
    function resetRedirectTimer() {
        timeout = 120000;
        window.clearTimeout(timer);
    };
    $(document).bind('idle.idleTimer', function () {
        $("#popup-modal").dialog({
            'modal': true,
            'autoOpen': true,
            'width': 574,
            'resizable': false,
            'draggable': false,
            'close': function (event, ui) {
                resetRedirectTimer();
            },
            'open': function (event, ui) {
                $('.ui-dialog-titlebar-close').hide();
                $('.ui-dialog-print').hide();
                $('.ui-icon').hide();
            },
            'show': {
                'effect': 'fade'
            }
        });
        timer = window.setTimeout(function () {
            window.location.href = 'redirectpage.xhtml';
        }, myTimeOut);
    });
    $(document).bind('active.idleTimer', function () {
        resetRedirectTimer();
    });
    $.idleTimer(timeout);
}(jQuery));

Also, you appear to be hiding the default controls for closing the dialog when the dialog is opened.
Do you still have a button (or other control) with which to close the dialog?

Finally, to clarify the problem, it looks like you want to redirect the user after 60 seconds of inactivity but cancel the redirect if they become active again.

Is that what you are trying to accomplish?

Hope this helps.

Pete

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文