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

144
Views
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
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!