Last active
August 23, 2018 22:40
-
-
Save itsalb3rt/5e6ebe5907d2c498d796d2c240aa6959 to your computer and use it in GitHub Desktop.
Cómo verificar la URL de la imagen 404 usando JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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