Add onerror handler to image element within document element array (IE) : img : HTML Tags JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » HTML Tags » img »

 

Add onerror handler to image element within document element array (IE)

















<html>
<head>
    <title>Image Error Test</title>
    <script type="text/javascript">
        function handleLoad() {
            document.images[0].onerror = function () {
                alert("An error occurred loading the image.");
            };

            document.images[0].src = "doesNotExist.gif";
        }
    </script>
</head>
<body onload="handleLoad()">
    <P>The image below attempts to load a file that doesn't exist.</p>
    <img/>
</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo HTML Tags
» img