本文介绍了Javascript自动注销代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有以下大部分代码都可以工作,但是我想知道是否有可能对其进行一些调整.因此,下面的代码要做的是,如果它们在x毫秒内没有鼠标活动,则会显示一个弹出窗口,提示他们将被注销,然后当/如果您最终单击ok按钮,脚本将自动将您带出注销文件.

I have the below code which works for the most part but I am wondering if its possible to tweak it a bit. So what the below code does is if their is no mouse activity for x number of milliseconds a popup window is displayed saying that they will be logged out and then when / if you eventually click the ok button the script will automatically bring you to the logout file.

但是,我想做的是,如果x毫秒后没有单击确定"按钮,只是继续将屏幕转到logout.php文件.任何人都知道我如何使用以下代码来做到这一点?谢谢

However what I would like to do instead is if the ok button is not clicked after x number of milliseconds just to go ahead and bring the screen to the logout.php file anyway. Anyone know how I might do this with the below code?Thanks

// Set timeout variables.
var timoutWarning = 840000; // Display warning in 14 Mins.
var timoutNow = 100000; // Timeout in 15 mins would be 900000.
var logoutUrl = 'logout.php'; // URL to logout page.

var warningTimer;
var timeoutTimer;

// Start timers.
function StartTimers() {
    warningTimer = setTimeout("IdleWarning()", timoutWarning);
    timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
}

// Reset timers.
function ResetTimers() {
    clearTimeout(warningTimer);
    clearTimeout(timeoutTimer);
    StartTimers();
    $("#timeout").dialog('close');
}

// Show idle timeout warning dialog.
function IdleWarning() {
//  $("#timeout").dialog({
    //modal: true
    alert("Warning, your page will redirected to login page. Due to not move your mouse within the page in 15 minutes.");
//});
}

// Logout the user.
function IdleTimeout() {
    window.location = logoutUrl;
}

推荐答案

从概念上讲,一次只需要运行1个计时器.一个计时器运行14分钟,另一个计时器运行另一分钟(总计15分钟).14分钟计时器用完后,将其杀死,然后启动1分钟计时器.如果那一分钟的计时器用完了,请注销用户.如果用户按下保持登录状态"按钮,请终止1分钟计时器并重新启动14分钟计时器.冲洗并重复.

Conceptually, you only need 1 timer running at a time. One timer that runs for 14 minutes and another that runs for another minute (15 minutes total). Once the 14 minute timer runs out, kill it and then start the 1 minute timer. If that one minute timer runs out, log the user out. If the user presses the "Stay Logged In" button, kill the 1 minute timer and restart the 14 minute timer. Rinse and repeat.

我已尽力更改了您的代码.希望你明白这一点.

I changed your code the best I could. Hope you get the point.

// Set timeout variables.
var timoutWarning = 840000; // Display warning in 14 Mins.
var timoutNow = 60000; // Warning has been shown, give the user 1 minute to interact
var logoutUrl = 'logout.php'; // URL to logout page.

var warningTimer;
var timeoutTimer;

// Start warning timer.
function StartWarningTimer() {
    warningTimer = setTimeout("IdleWarning()", timoutWarning);
}

// Reset timers.
function ResetTimeOutTimer() {
    clearTimeout(timeoutTimer);
    StartWarningTimer();
    $("#timeout").dialog('close');
}

// Show idle timeout warning dialog.
function IdleWarning() {
    clearTimeout(warningTimer);
    timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
    $("#timeout").dialog({
        modal: true
    });
    // Add code in the #timeout element to call ResetTimeOutTimer() if
    // the "Stay Logged In" button is clicked
}

// Logout the user.
function IdleTimeout() {
    window.location = logoutUrl;
}

这篇关于Javascript自动注销代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:09