Next generation's garbage RSS 2.0
# Thursday, January 24, 2008

I recently built a webpart that, among other things, displays an image, but the webpart really only generates the html to reference an image and it could not easily guarantee that the image would be available and I wanted to show something better than a red x.

By using a little script on the 'onerror' attribute for the img tag, I was able to reference a "image not available" picture in case the image failed to load.

Here's an example:

<img src="maybethisworks.jpg" onerror="this.src='/notavailable.gif';" />

That's it. It works on Opera9.5, Firefox2, IE7, Navigator9, and Safari3.

Edit: I felt panic when I noticed that all my images where coming up with the not available picture. After some flail I finally realized what was going on. The images were in a checked-out state which means that if I was authenticated they would appear, but if I was anonymous, they wouldn't and I would get the onerror behavior.

BTW: For anyone needing to perform check-in on many files (which is what you get after you upload a directory of images to a image library) you can use the "Manage Site Content and Structure" feature of MOSS which will allow you to do a mass check in.

Thursday, January 24, 2008 4:02:45 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
HTML
Comments are closed.
Archive
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
All Content © 2010, Hafthor Stefansson - Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. - Sign In