Image Loaded

[Total: 0    Average: 0/5]

This shows several of the methods available to the author to determine when and even if the image loads completely.

Body Code:

<script type=text/javascript>
var _pic = new Image();
_pic.onabort="picAborted()";
_pic.onerror="picError()";
_pic.onload="picLoaded()";
function isLoaded() {
  if (_pic.complete) alert(_pic.name+" has loaded");
  else alert(_pic.name+" has not loaded.");
}
function picError()   { alert("error");   }
function picLoaded()  { alert("loaded");  } // if already cached no event! its a gotcha!
function picAborted() { alert("aborted"); }
function clickMe() { _pic.src="http://www.js-examples.com/js/pic1.gif"; isLoaded() }
document.write('<BR><a href="javascript:clickMe()">CLICK ME</a>');
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *