Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Javascript onerror does not fire on image that throws 404

I have an image from a content provider that needs to be loaded or just replaced by the text.

Example: http://content.etilize.com/Brand-Logo/Black.jpg

This is a brand image that because it doesn't exist for this brand, it gets replaced via headers (from what I understand). So actual error event of image not loading does not happen.

<img src="http://content.etilize.com/Brand-Logo/Black.jpg" onerror="console.log('test')" />

Here is how the request looks like:

Image throws 404, but still loads after. Onerror event not triggered

So when I try to catch the not-loading 404 error, onerror does not trigger at all.

How can I capture this 404 status code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I suggest you to make a request using fetch, and checks the response status. If the status is OK, you just can create an img tag.

Like this example:

fetch('http://content.etilize.com/Brand-Logo/Black.jpg')
  .then((res) => {
    console.log(res)
    // create an <img/> tag using res 
  })
  .catch((e) => console.log("Impossible to load image")) 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!