Img on error works in safari but not firefox,(leopard) what can I doto fix that.

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>
 
V

VK

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).

In Firefox imgObject.onerror handler is intentionally killed in any
form, even for hardcoded in the source <img> elements (internal
security exception raised) - maybe to prevent any possibility of
content sniffing or I don't know. AFAICT nothing you can do about it.
Either screw on Firefox, or move your logic server-side which is
suggested: so get directory check results from server script over some
ajaxoid.
 
A

anne001

We would like to be compatible to most browsers. So I am interested in
the ajaxoid.

I am new to webprogramming (not to programming). I have several books
on ajax. Could you give me a few keywords to look for?

Right now I don't have a server script. I will have a serverscript to
receive the
user responses (sent through a form post). How would my html interact
with a serverscript on loading the images?

" get directory check results from server script over some ajaxoid"
 
V

VK

We would like to be compatible to most browsers. So I am interested in
the ajaxoid.

I am new to webprogramming (not to programming). I have several books
on ajax. Could you give me a few keywords to look for?

Right now I don't have a server script. I will have a serverscript to
receive the
user responses (sent through a form post). How would my html interact
with a serverscript on loading the images?

" get directory check results from server script over some ajaxoid"

I am actually surprised myself but this demo is pretty explicit:

<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<p><img src="foobar.gif" onerror="alert('error')"
onload="alert('Loaded')"></p>
</body>
</html>

If foobar.gif doesn't exist then onerror handling is silently
supressed in Firefox. Someone in Gecko team has chosen a "simple
solution" for the problem.

So your only option would be then to try to use XmlHttpRequest like
the one on www.ajaxtoolbox.com to see if you can catch 404 Not found
responses
But if XmlHttpRequest even allowed to request binary data? I don't
remember.
 
T

Thomas 'PointedEars' Lahn

anne001 said:
[...] What else can I use which would work on all browsers?

It is an illusion to think that anything would work on all browsers.


PointedEars
 
T

Thomas 'PointedEars' Lahn

anne001 said:
We would like to be compatible to most browsers. So I am interested in
the ajaxoid.

To be compatible to most browsers, you will have to abandon the notion of
the "ajaxoid".


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 11/29/2007 4:51 PM:

Pure nonsense.

It isn't. "Most" means the maximum possible coverage, and XHR ("the
ajaxoid") is not even necessary here.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 11/30/2007 12:48 PM:

I didn't say it was necessary.

So your reply was only for the sake of the argument?
I said the notion that to be compatible to "most browsers" means you have
to abandon AJAX is Pure Nonsense. The term for it is "graceful
degradation".

Graceful degradation implies that there were cases were AJAX would not work.
Abandoning AJAX would result in a solution that would be compatible in more
cases than not abandoning it.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 12/1/2007 5:38 AM:

Then why do you script at all?

You misunderstand. What I addressed was the notion of "most compatible".


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top