Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:36:07+00:00 2026-06-04T04:36:07+00:00

Question sounds quiet weird I know but here is the problem, the following code

  • 0

Question sounds quiet weird I know but here is the problem, the following code works perfectly. Timer starts at 30 minutes, every second a mouse move is not detected counts the timer down. When a mouse move is detected timer gets reset to 30 minutes, at the 25 minute mark of page inactivity a CSS popup shows counting down the last 5 minutes, at 30 minutes, the user gets auto logged out. However, if the user has the page open but is actively viewing another webpage altogether the timer either slows or stops altogether depending on the browser. Which in effect negates the script altogether. Is it possible to have the script continue its normal countdown and still force the user out of the page even if they aren’t actively viewing the page? Or are these browser quirks to reduce memory load?

 var Timing = 0;
 var CounterTime = 0;
 var TimePast = 0;
 var Seconds = 1800;
 var Warn = 1500;
 var MinuteLeft = 30;
 var SecondLeft = 60;
 var StopRefresh = 0;
 
 function ResponseTime()
 {
      Timing = Timing + 100;
      CounterTime = CounterTime + 100;
      if(Timing % 1000 == 0)
      {
            TimePast = TimePast + 1;
            SecondLeft = SecondLeft - 1;
            if(SecondLeft == 59)
            {
                 MinuteLeft = MinuteLeft-1; 
            }
            if(SecondLeft == 0)
            {
                 SecondLeft = 60;
            }
      }
      if(MinuteLeft != 0)
      {
            if(SecondLeft == 60)
            {
                  document.getElementById('CountdownTimer').firstChild.nodeValue = MinuteLeft+":00";
            }else if(SecondLeft < 10)
            {
                  document.getElementById('CountdownTimer').firstChild.nodeValue = MinuteLeft+":0"+SecondLeft;
            }else
            {
                  document.getElementById('CountdownTimer').firstChild.nodeValue = MinuteLeft+":"+SecondLeft;
            }
            if((MinuteLeft == 0) && (SecondLeft <= 10))
            {
                  document.getElementById('CountdownTimer').style.fontWeight = "bolder";
                  document.getElementById('CountdownTimer').style.color = "red";
            }
                  document.getElementById('CountdownTimer').style.fontWeight = "normal";
                  document.getElementById('CountdownTimer').style.color = "black";
            }else
            {
                  document.getElementById('CountdownTimer').firstChild.nodeValue = SecondLeft;
            if((MinuteLeft == 0) && (SecondLeft <= 10))
            {
                  document.getElementById('CountdownTimer').style.fontWeight = "bolder";
                  document.getElementById('CountdownTimer').style.color = "red";
            }else
            {
                  document.getElementById('CountdownTimer').style.fontWeight = "normal";
                  document.getElementById('CountdownTimer').style.color = "black";          
            }
      }
      if(TimePast == 1800)
      {
             document.getElementById('DoLogoutRequest').submit();   
      }
      if(MinuteLeft <=4)
      {
             document.getElementById('Overlay').style.visibility="visible";
             document.getElementById('ForceLogout').style.visibility="visible";
      }else
      {
             document.getElementById('Overlay').style.visibility="hidden";
             document.getElementById('ForceLogout').style.visibility="hidden";  
      }
      $(document).ready(function(){
             $(document).mousemove(function(){
                    Timing = 0;
                    TimePast = 0;
                    SecondLeft = 60;
                    MinuteLeft = 29;
             });
       });
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:36:08+00:00Added an answer on June 4, 2026 at 4:36 am

    What you could do is modify the script so that when a mousemove is detected, you first check the current number of seconds (using the Date object) since your last mousemove event.

    If it’s greater than 30 minutes, then you know the individual should be logged out, and then you can take that action immediately.

    Think of this like setting a tripwire that is armed at the 30 second mark but doesn’t fire until someone trips it.

    However, with that said, I really have strong concerns about how secure this methodology is. In general, the client side code is insecure. Things like automatically logging out a user should really be handled on the server side using a session.

    Still, this approach is creative in that it doesn’t force me to visit a different page. So, another technique you could use that would combine the server-side approach with the mouseevent approach would be to store the mouse movements, and the time, in a variable. Then, at your 29:30 minute mark, if the array contains a mouse movement that occurred in the last 25 minutes, make a secure AJAX request to the server to tell the session that the user is still active.

    This would reduce load on the server, since you’re only making that update when it’s needed, and it would also allow your users to use the application without needing to refresh to prevent logout, and it would also keep the actual “Is the user logged in” part of the logic where it belongs, on the server. If the server never hears a response from the client, the server will log the user out.

    In summary, instead of your server waiting potentially forever to hear that it’s okay to log the user out:

          if(TimePast == 1800)
          {
                 document.getElementById('DoLogoutRequest').submit();   
          }
    

    The server is taking a much more authoritative approach in moving on without you, if it doesn’t hear your client check-in:

          if(TimePast <= 1800 && TimePast >= 1700)
          {
                 // send keepalive request to the server to prevent auto-logout
    
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The question sounds weird I know. But its a weird question. Let me clarify.
I know the question sounds silly, but consider this: I have an array of
I know this sounds like a stupid question, but I really don't see the
The question probably sounds quite odd, and indeed it is. Here's the problem: I
This sounds like a simple question, but I don't know how to search for
This question sounds outrageous, but VS is giving me an error when I check
Apologies if the question sounds silly, I was following experts in SO and trying
Sorry if this question sounds a little silly, but I am not sure what
this might question might sounds stupid, but I could'nt figure it out. How can
Sounds like a stupid question, doesn't it? But the page on the Jettison project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.