PDA

View Full Version : image onerror compatibility


Dark-Talon
03-16-2003, 09:27 AM
Okay.. I wrote the following simple code to specify whether or not my personal server is online. It appears to work perfectly on IE for Windows, but I wrote this in Simpletext on my girlfriend's Mac, so I was able to test it there as well. Unfortunately, things didn't work out quite so well. Mac IE will display offline.gif even if the server is online. Safari will not display either image regardless of whether or not the server is online. This is exceptionally frustrating, as you might imagine, since this is a very simple function. I don't even really know what to do about this problem, but I don't suppose it's all that important, as my personal server is only available to my friends (for now).

function imageError()
{
document.serverstatus.src = "offline.gif";
}

...

<img name="serverstatus" onerror="imageError()" src="http://111.111.111.111/online.gif" border="0">

Why, oh why can't we establish standards for something as useful as javascript? :(

Dark-Talon

joh6nn
03-16-2003, 10:03 AM
try chaning the image name to an image id, and use getElementById() instead of document.imagename.

other than that, my only guess is that Safari and IE Mac don't like the ip address as the link. that's the only way the failure makes sense to me. have you tried googling for the problem? if not, try searching for "mac href ip" and for "mac image onerror". that might turn up documentation of the bug, if it's a bug, or suggestions on how to get this to work.

Dark-Talon
03-16-2003, 10:54 AM
Okay. I got it. It wasn't the IP address issue (I was testing it on another server, anyhow), and getelementbyid didn't work for me. Also, it should be noted that the Safari incompatibility was a strange glitch that corrected itself when toggling "Block popups" off and on.. it doesn't matter if it's on or off, but for some reason toggling it fixed the problem. Anyhow, below is the functional code.

function imageError(imageObj)
{
imageObj.src = "offline.gif";

}

. . .

<img onerror="imageError(this)" src="online.gif" border="0">

Dark-Talon