Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Local vs. Remote 1

Status
Not open for further replies.

jaschulz

Programmer
May 20, 2005
89
FR
I found a little image preload utility that works correctly only when the page is accessed remotely. The problem is with its error handling function. If one of the images to be preloaded is missing (and in the example I have posted, the image rockwell.jpg is not on the server), it should show an error message and quit. It does this correctly in all four browsers (FF2, IE7, Safari 3 and Opera 9) when the page is accessed remotely. But, I access the page locally (WinXP Pro SP2), IE7 and Safari 3 give the appropriate error, but Opera 9 runs the page and simply omits the missing image, while FF2 hangs and shows no message.

You can see a working example at:


there, of course, things work as they should. To see the problem, view and save the source and try loading the page locally. Obviously, you won't need the images since the idea is to generate the error, but if you want to see it work properly, you can edit line #13 and specify the images you want to use.

Thanks,

JAS
 
I imagine there's some oddity with Opera and loading images from a "file" protocol (I'm assuming you're using "file://" and not " on your local box?)...

I tried a quick search on Google for "opera image onload OR onerror local" to see what came back, and all I found were hints that things might not always work in all browsers if certain things are cached:

in some browsers (Opera and IE) the onload event fails to fire if the image is drawn from the cache rather than from the web

So maybe try clearing your cache before each test?

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I am not sure this is a cache problem. Unless I am mistaken, what is at issue is the way that FF responds to a failed image load (i.e. when myImage.src is set to a non-existent file name). All four browsers seem to cope with this error properly on the remote server, but locally, FF seems to do something peculiar (and Opera just blithely swallows the error and goes right on without a hiccough).

I am using this preload routine in a simple tool to meant to allow users to create a multiple-choice quiz and put it up on a web-site without messing with any server-side stuff (lots of teachers aren't very web-savvy, and anything on the server-side scares them off). If a user is preparing a quiz and testing it locally (and using Firefox), there will be no error if an image name is misspelled (for instance). I've nothing against the other browsers, but I want to be able to support Firefox first and foremost.

I spent a good part of this morning on Google trying to find some clue to this business, but I had no luck. I tried tracing the problem in Firebug and what I saw was an entirely sudden jump out to the javascript section to the first line of the (html) file (a pointer error?).

Maybe there is simply nothing I can do about this. I hope that's not true. What do you think?

Thanks,

JAS
 
Given the onerror event doesn't appear to fire in Fx for the file:// protocol, then you might have to use completely different logic.

Assuming the onload event fires, you could track all images and whether they have loaded or not, and when the page "onload" event fires, detect any which have not loaded.

Worth a shot!

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I get the idea. I'll give it a try.

Thanks,

JAS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top