Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda