THBBFT THBBFT - 2 months ago 5x
Javascript Question

A way to test if an IE7 based browser is online

I have an app with an embedded IE 7 browser. I need to test in a static HTML page, javascript is okay, whether the user has a connection to the Internet.

though an excellent library will not work here because the javascript is not supported.

window.navigator.onLine does not exist.

Simply using a
redirect is not an option because if the internet is not accessible I will be leaving the user on the current page. The logic should look something like this:

function UserIsOnlineTest(){
// needed code goes here
// boolean return value

if (UserIsOnlineTest()) {


The complete solution I ended up with (based on @RobM. answer)


var testImage= '';
var image = new Image();
var online = true;
image.src = testImage;
image.onerror = function() {
online = false;
if (online) {



If you have an image that you know should be online, you can create an image tag and have onerror indicate that the user is offline:

var googleLogo = '';
var image = new Image();
image.src = googleLogo;
image.onerror = function() {
   // user is offline