I wrote this to validate images. Basically it pulls the image on Id and sets the attribute to a url. It relies on the onerror function to determine if the url is a valid image and if not resets the src attribute to a generic location. Will this work? It is based off of two other SO posts….embedded javascript and validation simplification.
// a is the url that is checked
function validate_fav(a)
{
var img=document.getElementById('theimg');
document.getElementById('theimg').setAttribute('src', a);
img.onerror=function()
{
a=d+'/favicon.ico';
document.getElementById('theimg').setAttribute('src', a);
}
}
Found this link, wish I would have found this an hour ago
at
w3 schools
Just call a function on the onerror that resets the src to a generic image.