Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок0
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 ответ
+ 3
Add onerror handler
img.onerror = function()
{
element.innerHTML = "offline";
}
Reference:
https://www.w3schools.com/jsref/event_onerror.asp