Saturday, August 18, 2007

Image Detection, JavaScript, Safari and InnerHTML

Another cross-browser DOM tip. Safari (at least versions =< 3.x) can't handle innerHTML operations until the page has loaded.

Another tip. I ran into a situation where I had to verify that an image existed remotely. Apparently the image tag supports the "onerror" method, so if the image doesn't load you can point your onerror to a javascript function to do something about the image not being available. Example <img onerror="myfunc();" src="some source" /> onerror must be lower case else earlier versions of IE won't pick it up.

No comments: