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 except for:
- the bulk of it comes from one place, and I cannot change it
- the template around that HTML (including headers, footers, HEAD etc), the CSS, and Javascript is under my control.
- most images are under my control, and rendered separately from the untouchable HTML. These images come from local disk, and do not require the network. It can be assumed that these images are always available.
- the untouchable HTML contains images which would, ideally be displayed. If the network is unavailable, it is these images that would fail to load.
- the complete HTML file is likely to be stashed to disk, long before it is rendered. i.e. we cannot render different HTML based on network availability.
The app is likely to be offline for at least some of the time, so I wish to handle the case where images fail to load.
The images in question are predominantly 1x1 tracking images, but may include images that should be visible if they're available.
Without invoking JQuery, or an external library, what would you advise my plan of attack?
I have thoughts on how to do this, but realise that they are many pitfalls to worry about:
- with a CSS selector, select all the images that haven't loaded (is there such a selector?) and use
display:none;
. - with Javascript, set the
alt
attribute on every image to the empty string. This would need to be done ondocument.onLoad
? - check the availability of the network, and then using CSS hide all images with @href~=^http. I'm not sure how/when to apply this style.
If it helps, for this problem, I seem to have the following sub-problems. It is not clear the optimal strategy for any of them:
- 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.
- when to perform these tasks (e.g. when the document/window has finished loading?)
- how to apply them.
Any thoughts, code, suggestions would be gratefully received.