Papote
asked on
Tell if a server is online or offline in javascript
I have a Windows Mobile Device and want to make a local htm web page that detects if a server on the intranet is online or not. This is to tell if it is inside the WiFi area or not. I am using Pocket HPH as a local PHP and web server on the device but the PHP functions are very limited and cannot use fsockopen() and curl() is quite limited. I am thinking of using javascript. Opera Mobile 10 will be used as the main Web Browser on the device.
Download jquery and include it in your html page. then read http://api.jquery.com/jQuery.get/ about how to do an ajax request and execute a callback function if it was successful. let me know if that needs more explanation
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thats a pretty clever solution, much simpler than mine
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi,
Thats really cool solution from @leakim971 and @Graceful_Penguin.
Thats really cool solution from @leakim971 and @Graceful_Penguin.
ASKER
leakim971: Works pretty good on Opera Mobile, but not IE mobile. It doesn't matter since I'll be using it as default. The first time takes a long time if it is not found, because of the timeout.
Graceful_Penguin: Strangely, only works on IE
Graceful_Penguin: Strangely, only works on IE
Work on IE mobile :
(try to load a picture larger than 64pixel, wait for 3000ms, check the pic width and if it lower than 64pixel (no pic or "not found" pic) go to yahoo)
SO image.jpg need to be larger (width) than 64pixel
(try to load a picture larger than 64pixel, wait for 3000ms, check the pic width and if it lower than 64pixel (no pic or "not found" pic) go to yahoo)
SO image.jpg need to be larger (width) than 64pixel
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>INTRANET OR INTERNET</title>
</head>
<body>
<h1>PLEASE WAIT YOU'RE GOING ON THE RIGH PLACE...</h1>
<img id="pic" src="http://192.168.0.2/path/to/image.jpg" />
<script language="javascript">
setTimeout("if(document.getElementById('pic').width<64) window.location='http://www.yahoo.com'",3000);
</script>
</body>
</html>
ASKER
leakim971: Sorry I am not very good with javascript but I only see the false part to this code (Go to yahoo.com)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great but if the user hits the back button it won't automatically refresh the image.
I tried to force it to refresh, a little overkill, but doesn't always work.
I tried to force it to refresh, a little overkill, but doesn't always work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="cache-control" content="no-cache" />
<title>INTRANET OR INTERNET</title>
</head>
<body onload="body_Onload()">
<input id="hidReload" type="hidden" value="initialvalue" />
<h1>PLEASE WAIT YOU'RE GOING ON THE RIGH PLACE...</h1>
<img id="pic" src="http://192.168.0.2/path/to/image.jpg" />
<script language="javascript">
setTimeout("if(document.getElementById('pic').width<64) window.location='http://www.yahoo.com'; else window.location='http://www.google.com';",3000);
function body_Onload(){
if(hidReload.value!="initialvalue"){
window.navigate(document.location.href);
}else{
hidReload.value="newvalue"
}
}
</script>
<div id="picw">
</div>
</body>
</html>
>Works pretty good on Opera Mobile, but not IE mobile. It doesn't matter since I'll be using it as default
>Works great but if the user hits the back button it won't automatically refresh the image
Seems you don't want to close this thread...
:o(
>Works great but if the user hits the back button it won't automatically refresh the image
Seems you don't want to close this thread...
:o(
Thanks for the points!