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

145
Visualizações
Check if image from different website can be loaded

im trying to check if a image that is provided via a link is loaded or not. Here is how i currently check if its loaded or not:

$(`#${imgID}`)
    .on('error', function (err) {
        this.imageIsValid = false;
    })
    .on('load', function (res) {
        this.imageIsValid = true;
    });

I am loading a img element with a provided link and im listening for the two events 'error' and 'load' to check if the image is loaded. This does work for most of the images but not always. For example i have these two pictures:

Image one

Image two

Both these pictures trigger the 'load' event and are loaded on the page. But when i remove some part of the link the first image returns the 'error' event and the second one doesnt. The reason for this is, that the second link redirects to a empty image that is 16x9 px and therefore the 'load' event fires. The naturalHeight/naturalWidth and complete properties are also valid. For both images a 404 message gets logged in the console.

To check if the first request returns a bad response i then tried to check the img with a normal GET request. The problem here is that it works for the second image and but not for the first because now im getting cors errors. And if a request gets canceld by cors you cant get the response of the request.

So my question is: Is there another way to check if the image can be loaded or not.

about 4 years ago · Juan Pablo Isaza
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