Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Detect presense of dial-up internet connection in Javascript/DHTML/HTML

Posted on 2004-10-09
2
Medium Priority
?
172 Views
Last Modified: 2010-04-06
I'm trying to revamp my local homepage to incorporate an automatic option that detects the presence of an internet connection. In the case of an internet connection, the browser redirects to an internet website [in this case, gmail.com], and otherwise, it loads a page local to my computer.

Though i'm farirly javascript and html literate [assuming this is possible], a semi-lamen's termed walkthrough would be greatly appreciated. I really hope this is possible. Thanks.
0
Comment
Question by:jonnylentilbean
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
techjosh earned 500 total points
ID: 12426454
So, heres how it works... you set the imgsrc variable to an image that is always available when you are online.
You set the online_url to the url you want to go to if you are online and the offline_url to the url you want to go to if you're offline.

The javascript Image() object tries to download the image at imgsrc... if it can it runs the onload function... if it cant it runs the onerror function... if you cancel the page load it runs the onabort function... onabort and onerror both execute the offline function while onload executes the online function... hope its not too cryptic.

Also, if your browser caches the image it may report itself being online when you are really offline.

<html>
<head>
<title>Online test</title>
<script language=javascript>
<!--
var imgsrc = "http://www.google.com/images/logo_sm.gif";
var online_url = "http://www.google.com";
var offline_url = "c:\\offline.htm";

function TestConnection()
{
      var img = new Image();
      img.onabort = Offline;
      img.onerror = Offline;
      img.onload = Online;

      img.src = imgsrc;
}

function Online()
{
      alert ("You are online!");
      document.location.href = online_url;
}

function Offline()
{
      alert ("You are offline!");
      document.location.href = offline_url;
}

//-->
</script>
</head>
<body onload="TestConnection();">
<H1>Please Wait...</H1>
</body>
</html>
0
 
LVL 3

Expert Comment

by:techjosh
ID: 12427755
If you have a problem with your browser caching the image so that the page always says it's online you need to find an image that isn't cached... lots of dynamic images are like this.

try this image if you have this problem:
var imgsrc = "http://www.danasoft.com/vipersig.jpg";

If that fixes your problem you probably want to find another dynamic image as it might be considered rude to use his image and his bandwidth to see if you are online.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question