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 679565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:16:26+00:00 2026-05-14T01:16:26+00:00

im doing a little test to check whether the user is away (unactive) or

  • 0

im doing a little test to check whether the user is “away” (unactive) or not;

function away_status(){
    $("#away_stat_update").everyTime(1000, function(i) { 
        var number = Number($(this).html());
        if( number == 20 ) {
            // set user as away 
            alert( "user away" );
        }
        if( number > 20 ) {
            $("*").mousemove(function(e){
                $("#away_stat_update").html(0);
                var number = Number(0);
                // reset user to being online
                alert( "user back online" );
            });
        }
        $("#away_stat_update").html( number + 1 );
    });
    $("*").mousemove(function(e){
        $("#away_stat_update").html(0);
    });
}
away_status();

the only problem is that when the number is greater than 20 and the mouse is moved it keeps alerting “user back on line” instead of doing it just once. The number is resetting by the way.

  • 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-05-14T01:16:26+00:00Added an answer on May 14, 2026 at 1:16 am

    I’m answering this in a slightly different way – as I think it’s always nice to solve a problem gracefully and with the briefest possible code.

    This example does exactly what you want, fully working. It doesn’t write the number into the DOM, it holds it in memory in JavaScript – you can write it into the element if you wish to display the number, but this saves having to retrieve it each time.

    The alerts also work as you described.

    var number = 0;
    var timer;
    
    function handle_mouse_move() {
        if (number > 20) {
            alert("User back online, was away for approx " + number + " seconds");
        }
        number = 0;
    }
    
    function handle_timer() {
        if (number === 20) {
            alert("User away");
        }
        number++;
        timer = window.setTimeout(function() { handle_timer(); }, 1000);
    }
    
    $(document).ready(function() {
        timer = window.setTimeout(function() { handle_timer(); }, 1000);
    
        $("*").mousemove(function(e){
            handle_mouse_move();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was doing a little test to try Ruby's pty and I can't get
I am doing little assigment which involves fork,vfork and clone function. I need to
I'm creating a game with points for doing little things, so I have a
Im doing a little messing around and on a learning curve with Magento, Jquery
I'm doing a little bit of work on a horrid piece of software built
I am doing a little debugging, and so I want to log the eventArgs
I have been doing a little reading on Flow Based Programming over the last
I was doing a little research or googling for different methods of handling password
I was doing a little exploring of a legacy system I maintain, with NDepend
I'm doing a little game in Python 3.2 with use of PyQt. I needed

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.