I use a similar technique to publish @Sarfraz, but instead of hiding the elements, I just manipulate the upload image class.
<style type="text/css"> .loading { background-image: url(loading.gif); } .loaderror { background-image: url(loaderror.gif); } </style> ... <img id="image" class="loading" /> ... <script type="text/javascript"> var img = new Image(); img.onload = function() { i = document.getElementById('image'); i.removeAttribute('class'); i.src = img.src; }; img.onerror = function() { document.getElementById('image').setAttribute('class', 'loaderror'); }; img.src = 'http://path/to/image.png'; </script>
In my case, sometimes the images do not load, so I am handling the onerror event to change the class of the image so that it displays the background image of the error (and not the icon of the broken browser image).
Seth Jan 08 '11 at 18:44 2011-01-08 18:44
source share