Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在我的网页上设置超时会话时遇到问题_Javascript_Azure_Timer_Setinterval_Clearinterval - Fatal编程技术网

Javascript 在我的网页上设置超时会话时遇到问题

Javascript 在我的网页上设置超时会话时遇到问题,javascript,azure,timer,setinterval,clearinterval,Javascript,Azure,Timer,Setinterval,Clearinterval,我正在开发一个应用程序,如果用户在页面上未处于活动状态,则需要在一定时间后自行注销。我正在使用azure身份验证令牌,它将在一小时后过期。现在,我正在尝试设置两个计时器,第一个计时器将每一分钟运行一次,并将在每次鼠标操作时继续重置自身,第二个计时器应在58分钟不活动后加载,显示会话中只剩下120秒。我无法获得所需的功能,第一个计时器在1分钟后运行,但同时它也会启动第二个计时器 这是我的Javascript代码 <script> function timerModal() {

我正在开发一个应用程序,如果用户在页面上未处于活动状态,则需要在一定时间后自行注销。我正在使用azure身份验证令牌,它将在一小时后过期。现在,我正在尝试设置两个计时器,第一个计时器将每一分钟运行一次,并将在每次鼠标操作时继续重置自身,第二个计时器应在58分钟不活动后加载,显示会话中只剩下120秒。我无法获得所需的功能,第一个计时器在1分钟后运行,但同时它也会启动第二个计时器

这是我的Javascript代码

<script>

    function timerModal() {
        var count = 120;
        console.log("This has started");
        var counter = setInterval(timer, 1000); //1000 will  run it every 1 second

        function timer() {

            count = count - 1;
            if (count <= 0) {

                $(this).mousemove(function (e) {
                    count = 120;
                });
                $(this).keypress(function (e) {
                    count = 120;
                });
                clearInterval(counter);
                //vmsWebUtils.signOut();  //counter ended, do something here
                return;
            }

            document.getElementById("timer").innerHTML = count + " "; // watch for spelling
            console.log(count);
        }


    }

    var 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 => 57) { // 57 minutes
            $("#sessionTimeout").show();
                 timerModal();
        }
        console.log(idleTime);
    }


</script>

函数timerModal(){
var计数=120;
log(“这已经开始”);
var counter=setInterval(计时器,1000);//1000将每1秒运行一次
函数计时器(){
计数=计数-1;
如果(计数57){//57分钟
$(“#sessionTimeout”).show();
timerModal();
}
console.log(空闲时间);
}

我曾经要求站点具有相同的效果,如果有帮助,下面是代码。(设置为立即显示测试提示)

$('input')。按键(功能(e){
如果(e.which==13){
$(this.next('input').focus();
e、 预防默认值();
}
重置注销();
});
$('textarea')。按键(功能(e){
重置注销();
});
var autolog1=setTimeout(“logmeoutmsg()”,1);
var autolog=setTimeout(“logmeout()”,10000);
函数logmeout(){
window.location.href=“index.php?注销=1”;
}
函数logmeoutmsg(){
$(“#logoutmsg”).show();
var计数=10;
var counter=setInterval(计时器,1000);//1000将每1秒运行一次
定时器();
函数计时器()
{
$(#countdown”).html(count);
计数=计数-1;

如果(count我自己修改了它,下面是修改后的代码!! 很好用

<script>
    var idleTime = 0;
    var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
        $(this).mousemove(function (e) {
            idleTime = 0;
        });
        $(this).keypress(function (e) {
            idleTime = 0;
        });

    function timerIncrement() {
        idleTime = idleTime + 1;
        console.log(idleTime);
        if (idleTime > 2) { // 57 minutes
            clearInterval(idleInterval);
            timerModal();
            console.log("hello");
        }
        console.log(idleTime);
   }

    function timerModal() {
        var count = 120;
        console.log("This has started");
        var counter = setInterval(timer, 1000); //1000 will  run it every 1 second
        function timer() {
            count = count - 1;
            if (count <= 0) {
                clearInterval(counter);

                vmsWebUtils.signOut();  //counter ended, do something here
                return;
            }
            document.getElementById("timer").innerHTML = count + " "; // watch for spelling
            console.log(count);
        }
    }

</script>

var-idleTime=0;
var idleInterval=setInterval(timerIncrement,60000);//1分钟
$(this).mousemove(函数(e){
空闲时间=0;
});
$(此)。按键(功能(e){
空闲时间=0;
});
函数timerIncrement(){
空闲时间=空闲时间+1;
console.log(空闲时间);
如果(空闲时间>2){//57分钟
clearInterval(idleInterval);
timerModal();
console.log(“你好”);
}
console.log(空闲时间);
}
函数timerModal(){
var计数=120;
log(“这已经开始”);
var counter=setInterval(计时器,1000);//1000将每1秒运行一次
函数计时器(){
计数=计数-1;
如果(计数),请参见此处: