Connecting Tech Pros Worldwide Help | Site Map

validate image dimension in IE7

Josee
Guest
 
Posts: n/a
#1: Mar 1 '07
function validateImageDimension(path, expectedWidth, expectedHeight) {
var img = new Image();
img.src = path;
return (img.width == expectedWidth && img.height ==
expectedHeight);
}

function uploadCustomerLogo() {
var customerLogoFilePath =
document.getElementById("customerLogoFile").value;
if (!validateImageDimension(customerLogoFilePath, 160,
160)) {
alert('wrong size');
return;
}

I have this javascript to validate image dimension before uploading.
It was working fine in IE6. But it doesn't work anymore in IE7.
Because the image width and height is return as 0.

Anyone has idea how to fix this? Or a better way to do this?

Thanks

ASM
Guest
 
Posts: n/a
#2: Mar 1 '07

re: validate image dimension in IE7


Josee a écrit :
Quote:
function validateImageDimension(path, expectedWidth, expectedHeight) {
var img = new Image();
img.onload = function () {
return ( img.width == expectedWidth &&
img.height == expectedHeight )
}
Quote:
img.src = path;
}
>
function uploadCustomerLogo() {
var customerLogoFilePath =
document.getElementById("customerLogoFile").value;
if (!validateImageDimension(customerLogoFilePath, 160,
160)) {
alert('wrong size');
return;
}


--
Stephane Moriaux et son (moins) vieux Mac déjà dépassé
Stephane Moriaux and his (less) old Mac already out of date
Closed Thread