带有计时器的PHP Ajax自动注销 [英] php ajax auto logout with timer

查看:61
本文介绍了带有计时器的PHP Ajax自动注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
var t;
function startTimer(){
t=setTimeout("document.location='../login/logout.php'", 50000);
}

function  stopTimer(){
clearTimeout(t);
}
</script>

这是我的自动注销脚本,

This is my script for auto logout,

我想显示倒数计时器,如何创建和显示计时器

i want to show the countdown timer, How to create and show the timer,

当用户点击页面正文时,我也想活着,

Also i want to make alive when the user hit the body of the page,

还应该重置计时器,然后在系统空闲时重新启动,

Also timer should reset and then restart again when system is idle,

如何制作,

(计时器应显示,即, 计时器应该在人们不触摸系统时运行

(Timer should show , that is , timer should run when people not touching the system ,

如果用户触摸系统,则计数器应重新启动)

if user touch the system then counter should restart )

推荐答案

使用此功能:

function timer(elem, starttime, endtime, speed, funktion, count) {
    if (!endtime) endtime = 0;
    if (!starttime) starttime = 10;
    if (!speed) speed = 1;
    speed = speed * 1000;
    if ($(elem).html() || $(elem).val()) {
        if (count == "next" && starttime > endtime) starttime--;
        else if (count == "next" && starttime < endtime) starttime++;
        if ($(elem).html()) $(elem).html(starttime);
        else if ($(elem).val()) $(elem).val(starttime);
        if (starttime != endtime && $(elem).html()) setTimeout(function() {
            timer(elem, $(elem).html(), endtime, speed / 1000, funktion, 'next');
        }, speed);
        if (starttime != endtime && $(elem).val()) setTimeout(function() {
            timer(elem, $(elem).val(), endtime, speed / 1000, funktion, 'next');
        }, speed);
        if (starttime == endtime && funktion) funktion();
    } else return;
}

示例

timer("#timer", 50, 0, 1, function() {
    location.href = "../login/logout.php";
});

这篇关于带有计时器的PHP Ajax自动注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆