¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita0
How to catch error in javascript?
I'm trying to catch the error 404 of images that doesn't load on pinging a website. I want to print 'online' or 'offline' for the pings. Expected ouput: online online offline Result: online online My code: https://code.sololearn.com/WA20a816a4a1
1 Respuesta
+ 3
Add onerror handler
img.onerror = function()
{
element.innerHTML = "offline";
}
Reference:
https://www.w3schools.com/jsref/event_onerror.asp