Javascript examples for DOM HTML Element:Image
Handle image loading error by using onerror event
<html> <head> <title>A test</title> </head> <body> <img src="http://x.invalid" id="myImage"> <script> var imgs = [//from www .j a va 2 s. c o m "http://java2s.com", "https://www.google.com/images/srpr/logo11w.png", "http://www.java2s.com/style/download.png" ]; var imageIndex = 0; function tryNextImage() { var img = document.getElementById("myImage"); img.onerror = function() { imageIndex++; tryNextImage(); } img.src = imgs[imageIndex]; } tryNextImage(); </script> </body> </html>