How to display broken image icon in image-sized box?

Wayne Campbell 21 Reputation points
2022-01-27T21:07:41.203+00:00

I am trying to display broken image icons inside a box the size of the target image. Mozilla has the -moz-force-broken-image-icon: 1; property for doing this. Is there an equivalent property for this in Edge? Also, Firefox displays the alt text aligned with the top of the rectangle and wraps at the width of the rectangle instead of being at the bottom of the page and going offscreen (which is what Edge does). Is there a way to do this with Edge?

Edit: I noticed that on 2 pages that are virtually identical the alt text displays at the top on one and on the bottom of the other. The differences in the two pages are minimal and shouldn't have an effect on the position of the alt text. Why are they different?

Here are the two pages in question so you can see them side-by-side if you open them in different tabs.

3DModels.html
myModels.html

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,504 questions
{count} votes

Accepted answer
  1. Lan Huang-MSFT 29,746 Reputation points Microsoft Vendor
    2022-01-28T03:45:23.483+00:00

    Hi @Wayne Campbell ,
    1.You can try using JavaScript to manipulate the element's src attribute with the help of the onerror attribute of the img element. Whenever an image fails to load due to wrong src attribute URL, use JavaScript to replace the attribute with the desired URL.

     <div id="container"><img src="https://awik.io/my-image-disapp eared.jpg" one rror="handleBrokenImg(this);"/></div>  
    <script>  
            fun ction handleBrokenImg(el) {  
                el.src = 'https://awik.io/wp-content/uploads/2018/12/broken-img.png';  
            }  
    </script>  
    

    2.For text overflow problems, I think you can specify the length and width of <td 4>. The size of the missing image cannot be determined.
    If you can confirm it, you can directly set the size of <td 4> to the size of the image.
    3.You can press f12 and then click the screenshot location to view it yourself, or provide the source code.
    169307-2.png
    169294-3.png
    Below is the demo and code:169180-text.txt
    169321-3.gif
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.