Hiding images that failed to load

前端 未结 4 2006
执笔经年
执笔经年 2021-02-01 23:09

I have an Android application that generates some HTML which is rendered locally, in a Webkit view.

The details of the HTML generation aren\'t really that important exce

4条回答
  •  离开以前
    2021-02-01 23:35

    • how to determine the loaded-ness of the images or the state of the network.
    • how to hide/mask the failed to load images, such that it is not detectable by the user that the image is missing

    You may look at the onerror event which is triggered when an image fails to load:

    image
    
    • when to perform these tasks (e.g. when the document/window has finished loading?)
    • how to apply them.

    This worked for me in Firefox and Chrome when I added it ad the very end of my document (before ):

    var imgs = document.getElementsByTagName('img')
        for(var i=0,j=imgs.length;i

    It is quite posiible that if an image at the begining of your document didn't load, and you attach yor event handlers when the document is ready some browsers may not fire that handler - you should test it on your target platform.

提交回复
热议问题