Try this simple code. Handle OnError event of Image-
<img src="http://www.satya-weblog.com/image.png" height="100px" width="100px" onerror="this.src = '/image/item-no-image.png'" />
Or-
<img src="http://www.satya-weblog.com/image.png" height="100px" width="100px" onerror="handleMissingImg(this);" />
- function handleMissingImg(ele)
- {
- ele.src = '/image/item-no-image.png';
- }
Or, you can also use this-
- function IsImageOk(img) {
- // During the onload event, IE correctly identifies any images that
- // weren't downloaded as not complete. Others should too. Gecko-based
- // browsers act like NS4 in that they report this incorrectly.
- if (!img.complete) {
- return false;
- }
- // However, they do have two very useful properties: naturalWidth and
- // naturalHeight. These give the true size of the image. If it failed
- // to load, either of these should be zero.
- if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
- return false;
- }
- // No other way of checking: assume it's ok.
- return true;
- }
0 comments:
Post a Comment