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

  • Home
  • SEARCH
  • 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 7906359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:54:46+00:00 2026-06-03T10:54:46+00:00

I’ve written a small jQuery chatbox which loads a page in a div and

  • 0

I’ve written a small jQuery chatbox which loads a page in a div and refeshes every 4 seconds:

On click slide down and load page in div and refresh:

$('#toggle').click( function () { 
    $('#sbox').slideDown('fast');
    var refreshId = setInterval(function() {
        $('#shout').load('shout.php?randval='+ Math.random());
    }, 4000);
    return false;
});

This however I’m guessing is a bit of a resource drainer so thought how about after x minutes if no activity is detected stop refreshing but resume refreshing once there is activity again…

I found this snippet …
https://stackoverflow.com/a/7026769/1359310 …which checks for activity (mouse movement) and looks perfect for my needs but can’t seem to combine the two.

To summarize what I am after is on click load page in div and start refreshing, after x minutes if no activity stop refreshing, once activity is detected again start refreshing again.

  • 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-03T10:54:49+00:00Added an answer on June 3, 2026 at 10:54 am

    Something like this should do it. You should be able to adapt it to your needs. I essentially copied the code from the SO question you linked. This adds an active/inactive class to the body. You will see this when you run my code. When the page is active the screen is blue. This indicates refreshing takes place. When the screen is gray then don’t bother refreshing.

    Then you just put a check for the active/inactive class in your code.

    http://jsfiddle.net/scgEs/1

    var refreshrate = 4000;
    var inactivitytime = 15000;
    var refreshid; //set to global scope so that you can clear it later
    var activityTimeoutId; //store timeout for inactivity
    $('#sbox').slideUp();
    
    $('#toggle').click(function() {
        $('#sbox').slideDown('fast');
        refreshId = setInterval(function() {
            if ($('body.inactive').length == 1) {
                $('#sbox').append('<div>No refresh</div>');
            }
            else {
                console.log('Refreshing data');
                $('#sbox').append('<div>Refreshed...</div>');
                //$('#shout').load('shout.php?randval=' + Math.random());
            }
        }, refreshrate);
        return false;
    });
    
    // If theres no activity for X seconds do something
    activityTimeoutId = setTimeout(inActive, inactivitytime);
    
    function resetActive() {
        $(document.body).attr('class', 'active');
        clearTimeout(activityTimeoutId);
        activityTimeoutId = setTimeout(inActive, inactivitytime);
    }
    
    // No activity do something.
    
    
    function inActive() {
        $(document.body).attr('class', 'inactive');
    }
    
    // Check for mousemove, could add other events here such as checking for key presses ect.
    $(document).bind('mousemove', function() {
        resetActive()
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.