HTML if image is not found

后端 未结 16 2008
温柔的废话
温柔的废话 2020-12-07 13:46

I have an image in a HTML page:

\"Smiley

If the image is not found o

相关标签:
16条回答
  • 2020-12-07 14:22

    Well you can try this.

      <object data="URL_TO_Default_img.png" type="image/png">
       <img src="your_original_image.png" />
      </object>
    

    this worked for me. let me know about you.

    0 讨论(0)
  • 2020-12-07 14:22

    I added a parent div around the image and used the following onerror event handler to hide the original image because in IE there was still an ugly image-not-found image shown after using the alt attribute:

    <div style=" width:300px; height:150px; float:left; margin-left:5px; margin-top:50px;">
            <img src='@Url.Content("~/Images/Logo-Left.png")' onerror="this.parentElement.innerHTML = '';" />
    </div>
    
    0 讨论(0)
  • 2020-12-07 14:23

    I wanted to hide the space occupied by <img> tag so this worked for me

    <img src = "source.jpg" alt = "" >

    0 讨论(0)
  • 2020-12-07 14:25

    Solution - I removed the height and width elements of the img and then the alt text worked.

    <img src="smiley.gif" alt="Smiley face" width="32" height="32" />
    

    TO

    <img src="smiley.gif" alt="Smiley face" />
    

    Thank you all.

    0 讨论(0)
提交回复
热议问题