Skip to content

Instantly share code, notes, and snippets.

@itsalb3rt
Last active August 23, 2018 22:40
Show Gist options
  • Save itsalb3rt/5e6ebe5907d2c498d796d2c240aa6959 to your computer and use it in GitHub Desktop.
Save itsalb3rt/5e6ebe5907d2c498d796d2c240aa6959 to your computer and use it in GitHub Desktop.
Cómo verificar la URL de la imagen 404 usando JavaScript
$(document).ready(function(){
/**
* Determinar si una imagen existe por la propiedad naturalHeight
* la cual sera diferente de 0 si esta existe
**/
$('img').each(function(){
if($(this)[0].naturalHeight == 0){
//Reemplazar el src con la imagen que queremos presentar
$(this).attr('src','images/image_not_found.jpg');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment