Checking for an active Internet connection has a wonderful script that checks whether an Internet connection exists, then gives a readout (ONLINE or OFFLINE) to inform the user. Here is the code as it works in my app.

This section goes in between the <head> tags:

<!– from –>

<script type=”text/javascript” charset=”utf-8″>

function updateOnlineStatus(msg) {

var status = document.getElementById(“status”);

var condition = navigator.onLine ? “ONLINE” : “OFFLINE”;

status.setAttribute(“class”, condition);

var state = document.getElementById(“state”);

state.innerHTML = condition;

var log = document.getElementById(“log”);

log.appendChild(document.createTextNode(“Event: ” + msg + “; status=” + condition + “\n”));


function loaded() {


document.body.addEventListener(“offline”, function () {


}, false);

document.body.addEventListener(“online”, function () {


}, false);



The <body> tag is changed to:

<body onload=”loaded()”>

I use this code to place the notice where I want it:

<ul class=”rounded”>

<li><span style=”font-style:strong; color:white”>The following links require an active Internet connection.</span>

<div id=”status” ><p style=”font-family:Helvetica; color:yellow;” id=”state”></p></div>

<!–<div id=”log” style=”font-family:Helvetica”></div>–></li>


When the user visits this page and sees this area, he’ll see “ONLINE” or “OFFLINE” before clicking on any of the following Internet links.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.