Image Size from JavaScript to Classic ASP

I have spent the past day or so looking, thinking, and writing the perfect code that will return the dimensions of an image using JavaScript and place them in a cookie so that I may use it on an ASP page. Well after some research and thinking I came up with the following code.

<script type=”text/javascript”>
//Reference http://www.sovalid.com/blog
//Get and Assign Image
function GetImageSize(){
var img = new Image();
img.src = “http://www.google.com/intl/en_ALL/images/logo.gif”;
//Get Width and Height
wth = img.width;
hgt = img.height;

//Create the Two Cookies
document.cookie = “ImageWidth” + “=” +escape(wth)
document.cookie = “ImageHeight” + “=” +escape(hgt)

//Alert Width and Height as Test
wh=wth+” “+hgt;
alert(wh)
}

//Call Function
GetImageSize();
</script>

Reference my last post to see how to call the JavaScript cookie in Classic ASP. You can make the code as complex as you want this is just the basics, you can for example get the image from an ASP function instead of hard coding the image. You could also get the image from the page it self using document get element by id. Happy Coding.

One Response to “Image Size from JavaScript to Classic ASP”

  1. Danny  on September 9th, 2009

    Excellent Post