I am trying to select a random image from the following URL:
In order to display it correctly, I need to determine the size of the image.
I am utilizing YQL to store the JSON result in a variable (referred to as source).
After replacing 'https' with 'http' and removing all backslashes, this is how I proceed:
var it = $.parseJSON(source);
var total = it.count-1;
var random = Math.floor((Math.random()*total)+0);
var gagurl = it.items[random];
var gagurldecode = gagurl.replace('\\','');
gagurldecode = gagurldecode.replace('https','http'); //this is the image's URL
Unfortunately, I am unable to retrieve the dimensions of this image.
var img = new Image();
img.src = gagurldecode;
The line alert(img.height);
does not return anything.
If I change
img.src = gagurldecode;
to
img.src = 'http://d24w6bsrhbeh9d.cloudfront.net/photo/1777377_460s.jpg';
it works fine.
What am I doing incorrectly? PS: Apologies for any mistakes in my English!