Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda