/    Sign up×
Community /Pin to ProfileBookmark

Firefox problem with images.readyState

My site includes Javascript code to wipe out all images that did not download (i.e., were not found), so that annoying “missing image” icon does not appear. The code – curtesy of forum members – is simply this:

window.onload = function(){
for(var i=0; i<document.images.length;i++){
if(document.images[i].readyState!=’complete’){
document.images[i].src=’http://blablabla/spacer.gif‘;
}
}

where spacer.gif is a blank image. This works fine under IE, but on Firefox, it causes weird things: First, all images loas fine, then they ALL disappear, and the browser waits for the website forever. Once I remove that code, all works well.

It looks like the readyState property is not supported in Firefox. When I try to alert() it, it says undefined. [Incidentally, if I compare the value of an undefined object to a specific string, shouldn’t the result be false and the code in the if statement above not execute?]

So, how do I do this so it works under Firefox as well?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@7studFeb 12.2005 — Incidentally, if I compare the value of an undefined object to a specific string, shouldn't the result be false[/QUOTE]
How many seconds would that take to test?
Copy linkTweet thisAlerts:
@karayanauthorFeb 12.2005 — It would take no time at all! I obviously tested it, and

undefined == 'blabla'

comes up true (in Firefox, anyway).

My question was, shouldn't it come up false?
Copy linkTweet thisAlerts:
@7studFeb 12.2005 — You might want to re-evaluate your testing methods. What does the following script say when you run it in FF1.0?

if(undefined == "blabla") alert("equal");

else alert("not equal");
Copy linkTweet thisAlerts:
@karayanauthorFeb 12.2005 — SOrry, I meant to say undefined != 'blabla'. This is what I tested and it comes up true. Technically, that is correct. An undefined object value cannot be equal to a defined one, hence the != test is true. I guess, I would have expected FF not to even try to evaluate the expression and just raise an error (which it did) and stop executing (which it did not).

But all that is beside the point. My problem is, how do I do the empty image wiping in FF?
Copy linkTweet thisAlerts:
@ExuroFeb 12.2005 — Firefox doesn't display the broken image icons, so why don't you just provide [FONT=courier new]alt[/FONT] text for all your images and make the script run only in Internet Explorer?
×

Success!

Help @karayan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...