OCDProgrammer.com

It's Microsoft's World, and I'm just living in it
View Clarence Klopfstein's profile on LinkedIn

Clarence Klopfstein's Facebook profile

This site is under construction...

Categories

New Comments

Referring Sites


Disclaimer

  • This is MY blog. The views represented here are not in relation to anybody else. Please read my full disclaimer for a more complete disclaimer.

No image exist trick

January 3, 2010 20:54 by ckincincy

One of the neat little things I’ve learned on the big project I am on is how to show a default image if the one you need isn’t found.

To give a bit of a background, my last two jobs have been on catalog like websites.  Where you have thousands (on the bigger site… hundreds of thousands) of items in the catalog.  Each with several size variations of the image.  At my prior employer I had a pretty complex algorithm to determine if an image was available.  At the most basis level, querying the the hard drive to see if the file exist.   What I am using now is handled on the client side, and I tend to like the performance a bit more.

In a standard image tag, you have the following:

<img alt=”” src=”someimage.jpg” />

Adding a simple onerror tag to it, gives you a default image if the one you expect to be there doesn’t exist:

<img alt=”” src=”someimage.jpg” onerror=”this.onerror=null;this.src=’default.jpg’;” />

Pretty nice little trick, surprised I had never heard of it.


Comments

January 10. 2010 21:31

Neat. News to me as well. Neat trick though.

Rob |

Comments are closed