A
anne001
I am using Leopard
I found this code and am testing it as is. It works fine on safari
3.0.4 (gives an alert and then changes the missing picture icon to an
actual picture images/2.jpg), but not at all on firefox 2.0.0.10, no
alert, no swap of image (on Leopard). I am testing this because on a
larger script I put a missing image on purpose, firefox triggered the
"onload" fx even though the image was not there and the image shown
was the missing image icon!!? that is strange. On that larger script,
firefox did open an alert window, so that is not the problem?
What else can I use which would work on all browsers? I need the
scripting part mostly so I can preload and check 100s of pictures to
make sure they were all found.
I checked it in jslint, which did not like the inline part, but
removing it did not change anything
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Checking files</title>
<script type="text/javascript">
var imgsrc = 'picture1.gif';
var img = new Image();
img.onerror = function (evt) {
alert(this.src + " can't be loaded.");
};
img.onload = function (evt) {
alert(this.src + " is loaded.");
};
img.src = imgsrc;
</script>
</head>
<body>
<img src="p1.gif" onerror="this.onerror=null;this.src='images/
2.jpg';">
</body>
</html>
I found this code and am testing it as is. It works fine on safari
3.0.4 (gives an alert and then changes the missing picture icon to an
actual picture images/2.jpg), but not at all on firefox 2.0.0.10, no
alert, no swap of image (on Leopard). I am testing this because on a
larger script I put a missing image on purpose, firefox triggered the
"onload" fx even though the image was not there and the image shown
was the missing image icon!!? that is strange. On that larger script,
firefox did open an alert window, so that is not the problem?
What else can I use which would work on all browsers? I need the
scripting part mostly so I can preload and check 100s of pictures to
make sure they were all found.
I checked it in jslint, which did not like the inline part, but
removing it did not change anything
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Checking files</title>
<script type="text/javascript">
var imgsrc = 'picture1.gif';
var img = new Image();
img.onerror = function (evt) {
alert(this.src + " can't be loaded.");
};
img.onload = function (evt) {
alert(this.src + " is loaded.");
};
img.src = imgsrc;
</script>
</head>
<body>
<img src="p1.gif" onerror="this.onerror=null;this.src='images/
2.jpg';">
</body>
</html>