Forum Moderators: open

Message Too Old, No Replies

Checking for an internet connection

need som code

         

Andrew Thomas

9:56 am on Dec 9, 2003 (gmt 0)

10+ Year Member



Im creating a webpage in ASP to go onto a CD - I would like a piece of code thats automatically checks if the user has an internet connection/ping - If they do, i would like an email button to appear if no connection a print button to appear.

any help appreciated

thanks

edicius

9:22 pm on Dec 9, 2003 (gmt 0)

10+ Year Member



Well this is more of a hack than a solution - since I've never had the need for this type of functionality on any of my pages I don't have any 'pretty' code to look at. At the very least the script below should give you some ideas.

If you need me to clarify what it's doing let me know...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Test Online/Offline JavaScript</title>
<SCRIPT LANGUAGE="JavaScript">
//identify the element based on browser type
isNS4 = (document.layers)? true : false;
isIE4 = (document.all &&!document.getElementById)? true : false;
isIE5 = (document.all && document.getElementById)? true : false;
isNS6 = (!document.all && document.getElementById)? true : false;


function switchDiv(strDivName, bolVisible){
if (isNS4) {
objElement = document.layers[strDivName];
} else if (isIE4) {
objElement = document.all[strDivName];
} else if (isIE5 ¦¦ isNS6) {
objElement = document.getElementById(strDivName);
}
if(isNS4){
if(!bolVisible){
objElement.visibility ="hidden";
}else{
objElement.visibility ="visible";
}
}else{
if(!bolVisible) {
objElement.style.visibility = "hidden";
}else{
objElement.style.visibility = "visible";
}}}


function imageError(imgURL) {
switchDiv('Print_btn', true);
switchDiv('Email_btn', false);
}
</SCRIPT>
</head>
<body>
<img name="logo" src="http://google.com/images/logo.gif" border="0" height="0" width="0" onLoad="switchDiv('Print_btn', false);" onError="imageError(this)" onAbort="imageError(this)">
<button id="Print_btn">Print</button>
<button id="Email_btn">Email</button>
</body>
</html>

Andrew Thomas

9:23 am on Dec 10, 2003 (gmt 0)

10+ Year Member



Thankyou, I can understand what the program is trying to do, however i get an error

on the line <img name="logo"......

line 1 char 1 - object expected.

thank you for your help

As you can see im not to familiar with javascript yet :)

edicius

1:48 pm on Dec 10, 2003 (gmt 0)

10+ Year Member



It appears that we've fallen victim to the Forum reformat/character replace rules!

On line 18 the '¦¦' is supposed to be two "pipe" characters - not the character that they've been replaced with.

If you can't figure the change out - you can split this statement into two:

REPLACE:


} else if (isIE5 ¦¦ isNS6) {
objElement = document.getElementById(strDivName);
}

WITH:

} else if (isIE5) {
objElement = document.getElementById(strDivName);
} else if (isNS6) {
objElement = document.getElementById(strDivName);
}

Andrew Thomas

3:50 pm on Dec 11, 2003 (gmt 0)

10+ Year Member



thanks - its fine now