My javascript code like this :
function detect(URL) {
var image = new Image();
image.src = URL;
var x = image.onload = function() {
console.log(image.naturalWidth)
console.log(image.naturalHeight)
if(image.naturalWidth==275 && image.naturalHeight==233)
return true
return false
}();
return x;
}
console.log(detect('https://www.roseindia.net/javascript/appendChild-1.gif'));
Demo and full code like this : https://jsfiddle.net/ctnq03g3/
The result of console.log(image.naturalWidth) = 0 and console.log(image.naturalHeight) = 0
Should it have value 275 and 233
I make the code like that, because I want the detect method return true or false
How can I solve this problem?