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

3rd Jul 2021, 11:17 AM
Adarsh Mamgain
Adarsh Mamgain - avatar
1 Resposta
+ 3
Add onerror handler img.onerror = function() { element.innerHTML = "offline"; } Reference: https://www.w3schools.com/jsref/event_onerror.asp
3rd Jul 2021, 12:29 PM
Ipang