Hiding images that failed to load

前端 未结 4 2007
执笔经年
执笔经年 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:12

    how to determine the loaded-ness of the images or the state of the network.

    One approach may be to maintain references all of the images in the DOM and bind an onload event which is fired when the image has finished loading. After a specified amount of time, any image which hasn't fired can be assumed to be problematic.

    how to hide/mask the failed to load images, such that it is not detectable by the user that the image is missing.

    You've already mentioned some options. Have you thought about removing the element from the DOM altogether? Client will no longer attampt to load the image.

    when to perform these tasks (e.g. when the document/window has finished loading?)

    You cannot use the document or window onload events because that won't fire until everything on the DOM has loaded. Checking the readiness of the DOM varies between browsers (Lucky you're only dealing with one!). This might get you started.

提交回复
热议问题