Javascript get image height works in all browsers but firefox...please help?

Posted by Calvin on Stack Overflow See other posts from Stack Overflow or by Calvin
Published on 2011-01-16T08:44:23Z Indexed on 2011/01/16 8:53 UTC
Read the original article Hit count: 165

Filed under:
|
|
|

So I am fairly new to Javascript (a lot of experience in PHP), but I have this basic script that checks a link that redirects to a URL to see what the image height is. If it is a certain height then it adds one to a variable, otherwise nothing. I would easily do this in PHP but the images are on other servers and not my own so it doesn't work.

Anyways, ehre is the script. Let me know if you have any tips. Works well and tested in Chrome, Safari, Opera, and IE.

<script language='JavaScript'>
window.onload = function() {

var nstar = 0, urls = [];
urls[0] = "http://optout.imiclk.com/cgi/nai_status.cgi?nocache=";
urls[1] = "http://www.adbrite.com/mb/nai_optout_check.php?nocache=";
urls[2] = "http://events.adchemy.com/visitor/auuid/nai-status?nocache=";

function getImgSize(imgSrc){
    var newImg = new Image();
    newImg.src = imgSrc;
    return{height:newImg.height, width:newImg.width}
}

for(i=0,length=urls.length;i<length;i++){
    if(getImgSize(urls[i]).height==43){nstar++;}
}
document.getElementById('tracknum').innerHTML = "<b>" + nstar + "</b>";

}               

</script>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about image