Roger Withnell wrote:
I browse for an image using form input type file and call a JavaScript
function with onchange.
I then want the function to check the image's properties (width, height,
filesize).
In WinIE, the following works:
var myimage = new Image();
myimage.src = fileID.value; // fileID is the form input type file ID, passed
to the function with getElementById( 'file')
alert(myimage.w idth); //gives the pixel width of the file (or height or
fileSize).
This does not work in Netscape or Safari.
You can't access an image's attributes milliseconds after you set it's SRC
attribute. The browser can't know what the dimensions of the image are until
it's (down)loaded the image, and that does not happen instantaneously .
How do obtain these properties in Netscape and Safari?
Use the browser's ability to inform you when the image is done (down)loading the
image using the image's -onload- event:
var myimage = new Image();
myimage.onload = function() {
alert(this.widt h);
}
myimage.onerror = function() {
alert('Image did not load!');
}
myimage.src = 'path/to/the/image';
You won't be able to obtain the image's -fileSize-, that attribute is only
available on a limited subset of browsers (possibly only IE, maybe a very few
others that attempt to mimic IE's abilities).
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ -
http://jibbering.com/faq