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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:53:29+00:00 2026-06-16T14:53:29+00:00

I have an unusual problem. I’m using the following script to check for internet

  • 0

I have an unusual problem. I’m using the following script to check for internet connection using navigator.onLine. If there is internet connection, the page will be refreshed every 15 seconds. If there isn’t any internet connection, the page will use innerHTML to display a message.

<script type="text/javascript">
setInterval(function () {
if (navigator.onLine) {
var myInterval = setInterval(function(){window.location.href = "Tracker.html";},15000);
} else {
clearInterval(myInterval);
var changeMe = document.getElementById("change");
change.innerHTML = "<big><font face='Arial' color='#ffffff' size='2'><center>OFFLINE</big><br>No internet connection</font></center>";
}
}, 250);
</script>

My problem is, once there is no internet connection, the message will be displayed, BUT the page would still be refreshed one last time. I’m trying to avoid this, by using clearInterval(myInterval); in the else part of the code, however it won’t work.

Any suggestions?

  • 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-16T14:53:30+00:00Added an answer on June 16, 2026 at 2:53 pm

    To refresh the page at 15 second intervals (provided that a connection is present), use:

    function refresh() {
        if(navigator.onLine)
            window.location.href = "Tracker.html";
        else{
            var changeMe = document.getElementById("change");
            change.innerHTML = "<big><font face='Arial' color='#ffffff' size='2'><center>OFFLINE</big><br>No internet connection</font></center>";
            setTimeout(refresh, 250);
        }
    }
    setTimeout(refresh, 15000);
    

    At the end of 15 seconds, this checks whether a connection is present. If there is, it refreshes the page. If there isn’t, it proceeds to check every 250 milliseconds afterwards until the user is reconnected, at which point it refreshes the page.

    The net result is that the script refreshes the page as soon as possible after a minimum of 15 seconds have elapsed.

    Here is a demonstration: http://jsfiddle.net/JGEt9/show

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unusual problem with my views - after a while of using
I have encountered a slightly unusual problem. Consider the following code: class parser {
I have an unusual problem with a form (here's a slimmed down version): <script>
I have little unusual problem to solve. I need some hint or links to
i have an really unusual problem i've never had before. i've no .htaccess file
I have a rather unusual problem, and it is hurting my brain. Problem: Given
I have an unusual problem. Let's consider such models (taken from django docs): class
I have a somewhat unusual problem. In my app, I am shadowing a UIImageView
I have a unusual problem throwing an exception An attempt was made to load
I have a quite unusual problem with the rendering of a textarea-field in Firefox.

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.