Image API not working

A script is supposed to read an image URL from a div data-src attribute:

(function() {
var jalObj = document.querySelector('.c-jalousie');
var imgSrc = jalObj.getAttribute('data-img-src');
console.log("imgSrc =", imgSrc);
})();

So far, that works. But as soon as I try to get into the native Image() API with img.onload, that part seems to never reached nor executed:

  // Load the image
  var loadImg = new Image();  
  loadImg.onload = function() {
    // this part is never executed. Why?
    console.log('checking onload status');
  }
  loadImg.src = imgSrc;

Can’t find out why that doesn’t work. Does anyone else here have a hint for me?
I also made a Pen: http://codepen.io/rowild/pen/vyVmYN?editors=1111

Thanks!!

Try to use

var loadImg =Object.create(Image);

With previous instantiation of loadImg i have the following console output
“imgSrc =” “http://www.wallpaperstop.com/wallpapers/space-wallpapers/cool-space-wallpaper-1680x1050-1009158.jpg”
“loadImg.src =” “”

With this that i suggest you i have this:
imgSrc = http://www.wallpaperstop.com/wallpapers/space-wallpapers/cool-space-wallpaper-1680x1050-1009158.jpg
loadImg.src = Function {scr: “http://www.wallpaperstop.com/wallpapers/space-wallpapers/cool-space-wallpaper-1680x1050-1009158.jpg”}

downloadingImage.scr = jalObj.getAttribute('data-img-src');

Should be downloadingImage.src ;-)

1 Like

Hell no!!! Two days of blindness! And I am sure nobody believes me now that I actually used to work as a proof reader…

Thank you very much!!!

1 Like

@lionitas76 Thank you for your feedback! Interesting point - I’ll keep that in mind!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.