show countdown time form jquery session timeout

前端 未结 1 1730
清歌不尽
清歌不尽 2021-01-16 03:56

I\'ve found https://github.com/travishorn/jquery-sessionTimeout this jquery session timeout that I want to use in my project.

It looks work fine in background, altou

相关标签:
1条回答
  • 2021-01-16 04:29

    Try this

    var SessionTime = 10000;
    var tickDuration = 1000;
    
    var myInterval = setInterval(function() {
        SessionTime = SessionTime - tickDuration
        $("label").text(SessionTime);
    }, 1000);
    
    var myTimeOut = setTimeout(SessionExpireEvent, SessionTime);
    
    $("input").click(function() {
        clearTimeout(myTimeOut);
        SessionTime = 10000;
        myTimeOut = setTimeout(SessionExpireEvent, SessionTime);
    });
    
    function SessionExpireEvent() {
        clearInterval(myInterval);
    
        alert("Session expired");
    }
    

    See this jsFiddle example.

    0 讨论(0)
提交回复
热议问题