1

I have worked in capturing the user in the application, after login.

  • After login I capture the users session with JavaScript's interval functions

    1. The Interval functions trigger every minute.

      • when the users session exceeds 1 minute in the app, it should to show a warning message with a count down for the remaining minutes
      • when the countdown is working properly for the first couple of seconds and then hit the interval function, the count down have a flickering problem.

      • Session Timeout 3:0 minutes, Here when click the button and after 1 minutes show the countdown will be visible and it reaches some seconds, there have a flickering problem.

Code:

loading= function(){  
   var lastDigestRun = Date.now();  
      var idleCheck = setInterval(function () {           
           alert('interval function invoked');
          var now = Date.now();
          var displaytime = now - lastDigestRun > 3 * 60 * 1000;
          if (now - lastDigestRun > 1 * 60 * 1000) {
           alert("warning alert");
              load();
          }
          if (now - lastDigestRun >3 * 60 * 1000) {
              alert("logout");
          }

  }, 60 * 1000); 

load = function () {  
  startTimer(2,0);              
  function startTimer(m,s)
  {
  document.getElementById('timer').innerHTML= m+":"+s;
    s == 0 ? (m == 0 ? alert('done') : (m--, s=60, t())) : (s--, t());
    function t(){ setTimeout(function(){startTimer(m,s)},1000)};
  }

};

Please also look at this JSFiddle

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71
  • 1
    1. Never alert in a script using interval or setTimeout - instead use console.log when debugging. 2. use different variable to store the handle: `var tId1 = setInterval...; var tId2 = setInterval...` - then you can clearInterval(tId1) and clearInterval(tId2) - in this case it looks like you you keep starting intervals – mplungjan Dec 07 '16 at 12:54
  • @mplungjan for reference i have set the alert , without alert also flickering happens in some minutes. can you look into the fiddle and update your solution if you have time – Mohamed Sahir Dec 07 '16 at 13:10
  • Your code is completely opaque. For sure you are running far too many setintervals. when you call t() and startimer and load – mplungjan Dec 07 '16 at 13:16
  • i'm not getting wht you are saying , One interval is for capturing the user session before two minutes timeout function triggered for user count down. i have cleared the intervals in before load function. still flickering occurs. – Mohamed Sahir Dec 07 '16 at 13:29
  • @MohamedSahir Did you intend to add the angularjs tag to this question? There is nothing relating to angular in the question, and if you are using angular then using `setInterval` or `innerHTML` in your javascript are both very bad ideas. Use `$interval` to update your model values and use angular's directives to insert the time in the timer element. – Duncan Dec 07 '16 at 14:24
  • @duncan ,i am worked on angular app using the $interval there inside rge run block, but just for understanding the problem with timeout and interval count down i have implemeted the solution in javascript. Thanks for your suggestion. i will try it as directive count-down. – Mohamed Sahir Dec 07 '16 at 14:57

0 Answers0