Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI all ,

we are binding images in one of the list in asp.net \MVC. it works fine if image is found from the folder. but when we dont found images in the folder it shows X in the IE / chrome to show that image not found.

we apply alt text as string empty so that it wont show any broken image or X on browser. this works fine on Mozila but not on IE and Chorme.

can some buddy help me please ?
Posted
Comments
JoCodes 28-Feb-14 7:56am    
Have you tried a fallback image logic if the image doesnt exists?

Apparently it's some kind of Webkit bug.

You can use the onerror property to hide the image (or replace it)
JavaScript
function onError(img) {
    delete img.onerror;
    // Change the url
    //img.src = 'images/noload.jpg';
    
    // or just hide it (jQuery)
    //jQuery(img).hide();
}

HTML
<img src="http://dev.null" onerror="onError(this)">
 
Share this answer
 
v2
Comments
ravikhoda 28-Feb-14 8:03am    
i even do not want to show some other image like noimage.png.
Maarten Kools 28-Feb-14 8:04am    
So hide it. The point of the example is that you can use the onerror event to detect a load error, and then to handle it accordingly.
ravikhoda 28-Feb-14 8:08am    
okay thanks let me try .
Probably you may try this link

jquery-javascript-to-replace-broken-images[^]
 
Share this answer
 
Comments
ravikhoda 28-Feb-14 8:03am    
i even do not want to show some other image like noimage.png.
JoCodes 28-Feb-14 8:10am    
The link replaces broken images in OnError event. So use the event to push your logic.
ravikhoda 28-Feb-14 8:21am    
alright thanks let me try that.
JoCodes 28-Feb-14 8:27am    
Welcome. Try and Revert if need some help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900