Validating availability of Picture on the internet

I am developing a gadget to display an image on the Sidebar. It works fine if the image is available (I just set the src to the url of the object).

My question is this: Is there a way to validate that a url is valid prior to setting the src value to it If the image is not available I would like to show an image to the user rather than get the default image with the little x.

I have this functionality working in a Yahoo Widget but am not sure how to go about implementing it in a gadget.

Thanks for any help you can provide.

Mark



Answer this question

Validating availability of Picture on the internet

  • hrubesh

    Did a little digging and found that I can set the on error handler for the picture to call a javascript function to set the src property to a file that is stored within the gadget.

    Thanks anyways.


  • jmcdonaldtucson

    Hope this helps...

    (Mine.png can be changed to any file within your gadget...)

    <html>
    <head>
    <title>Image Test</title>
    <style>
    body
    {
    margin: 0;
    height: 100;
    width: 100;
    }
    </style>
    <script>

    function ImageError(){
    myImage.src="Mine.png";
    }


    function load(){
    myImage.onerror=ImageError;
    myImage.src="http://www.microsoft.com/myImage.jpg";
    }

    </script>
    </head>

    <body onload="load();">
    <table cellpadding="1" cellspacing="1" border="0" class="normal">
    <tr>
    <img id="myImage" height=100 width=100/>
    </tr>

    </table>

    </body>
    </html>


  • payal tandon

    Could you post the code how you did this
  • Validating availability of Picture on the internet