search

Home  >  Q&A  >  body text

javascript - Why does Firefox not display the image placeholder that failed to load?

404 for loading images on the

page, a placeholder for loading failure will be displayed under Chrome and IE (as shown in the picture), so that users can directly see that there are images being loaded. Failed, but why doesn't Firefox display a similar placeholder?

阿神阿神2751 days ago1115

reply all(2)I'll reply

  • 漂亮男人

    漂亮男人2017-05-19 10:35:43

    Firefox is special, you can try the following activation method
    Enter about:config in the address bar to find browser.display.showimageplaceholders, and set the value to true

    In addition, if the picture is not displayed, it is best not to use placeholders. You can try several methods to give the default picture when the picture fails to load.

    Method 1

    Lazy loading method, determine whether the real img is loaded successfully before src assignment

    Method 2

    Convert a small amount of img

    `<img src='real.jpg' alt='test' onerror="this.src='default.jpg'">
    `

    Batch img conversion
      $('img').error(function(){
                $(this).attr('src', "default.jpg");
             });

    reply
    0
  • ringa_lee

    ringa_lee2017-05-19 10:35:43

    Firefox directly displays the content in alt, and does not have a default picture like IE/Chrome

    reply
    0
  • Cancelreply