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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:52:35+00:00 2026-06-15T23:52:35+00:00

I have many websites running my shoutbox script, but there is a problem here:

  • 0

I have many websites running my shoutbox script, but there is a problem here:

This shoutbox refreshes itself each 10 seconds , and consider what if it happens on a crowded website!

It gives javascript error sometimes to some users

$(document).ready(function(){
updateShoutbox();
var auto_refresh = setInterval(
function ()
{
updateShoutbox();
}, 10000);

Changing the time period is one option , the other is improving the server resources . but I have a thesis here:

What if there is a way to smart up this thing as it could stop refreshing while the user is disconnected or not focused on the website window ?

I am looking for a way to condition the shoutbox refresh to only when the website window is focused and internet connecton is alive .

Thanks for the help.

  • 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-15T23:52:36+00:00Added an answer on June 15, 2026 at 11:52 pm

    In a small search I found this javascript implementation that detects when the user is idle or away.

    Example:

    var auto_refresh = null;
    $(function(){
    
        setIdleTimeout(2000); // 2 seconds
        setAwayTimeout(4000); // 4 seconds
    
        document.onIdle = function() { /* something on idle if you want */ }
        document.onAway = function() { if(auto_refresh != null) clearInterval(auto_refresh); }
        document.onBack = function(isIdle, isAway) { auto_refresh = setInterval("updateShoutbox();", 10000); }
    
        updateShoutbox();
        document.onBack();
    });
    

    You can stop sending ajax requests when the user is away using this implementation.


    Answering the comment:

    OK, but I thought the more relevant part to the question asked is how
    this library works and what it detects and I thought expounding upon
    that would make a more useful answer. If I was the OP, I’d want to
    know how does it detect onIdle and onAway and onBack and are those
    even relevant to my problem? – jfriend00

    jfriend00, it tracks the interactive events in the document, using jQuery or prototype api:

    function _initJQuery()
    {
        _api = _API_JQUERY;
        var doc = $(document);
        doc.ready(function(){
                doc.mousemove(_active);
                try {
                    doc.mouseenter(_active);
                } catch (err) { }
                try {
                    doc.scroll(_active);
                } catch (err) { }
                try {
                    doc.keydown(_active);
                } catch (err) { }
                try {
                    doc.click(_active);
                } catch (err) { }
                try {
                    doc.dblclick(_active);
                } catch (err) { }
            });
    }
    
    function _initPrototype()
    {
        _api = _API_PROTOTYPE;
        var doc = $(document);
        Event.observe (window, 'load', function(event) {
            Event.observe(window, 'click', _active);
            Event.observe(window, 'mousemove', _active);
            Event.observe(window, 'mouseenter', _active);
            Event.observe(window, 'scroll', _active);
            Event.observe(window, 'keydown', _active);
            Event.observe(window, 'click', _active);
            Event.observe(window, 'dblclick', _active);
        });
    }
    
    // Detect the API
    try {
        if (Prototype) _initPrototype();
    } catch (err) { }
    
    try {
        if (jQuery) _initJQuery();
    } catch (err) { }
    

    Then it use timeouts to track when the user didn’t interact with the page, basically, if the user interact before the timeout is executed, then the function clear the timeout and start it again, so it’s only executed when the user don’t interact with the page:

    function setIdleTimeout(ms)
    {
        _idleTimeout = ms;
        _idleTimestamp = new Date().getTime() + ms;
        if (_idleTimer != null) {
        clearTimeout (_idleTimer);
        }
        _idleTimer = setTimeout(_makeIdle, ms + 50);
        //console.log('idle in ' + ms + ', tid = ' + _idleTimer);
    }
    

    When the user get back, it interact with the page, detect that he was away or idle by a flag, if he was away then he executes the onBack and start the setTimeout again

    function _active(event)
    {
        var t = new Date().getTime();
        _idleTimestamp = t + _idleTimeout;
        _awayTimestamp = t + _awayTimeout;
        //console.log('not idle.');
    
        if (_idleNow) {
        setIdleTimeout(_idleTimeout);
        }
    
        if (_awayNow) {
        setAwayTimeout(_awayTimeout);
        }
    
        try {
        //console.log('** BACK **');
        if ((_idleNow || _awayNow) && document.onBack) document.onBack(_idleNow, _awayNow);
        } catch (err) {
        }
    
        _idleNow = false;
        _awayNow = false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to add certificate to IIS 6.0. But there are many other websites
I hope this question isn't too dumb. We have many websites internally that need
I have looked on many websites but none of them seem to work right
I have started using ajax/jQuery in our websites / application. There are many plugins
Many websites have very good looking pop-up window. For example checkout http://www.myntra.com and when
We have 19 websites, many of which have many virtual directories, on a IIS
How do many of the websites that have logins keep the username in the
As many of you know, there are quite a few websites that sell royalty
I have made this batch script which will allow the user to enter a
Hello Everyone, I have made so many Flash presentations, but every time i stuck

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.