The use of the picture size and picture sizes (height and width) to note that the picture must be completed before JS get the picture width and height, so to judge in the readystate== "complete" state to get the size, if it is to use file upload, Always click to clear image=new image (); Imgage.width and Height Oh.
<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd" >
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title>js get picture sizes and picture sizes (height and width) </title>
<script>
function Checkimg (IMG)
{
var message= "";
var maxwidth=1;//set Picture width limit
var maxheight=1;//set Picture height limit
if (img.readystate!= "complete") {
Return false;//ensure the picture is fully loaded
}
if (img.offsetheight>maxheight) message+= "R height Excess:" +img.offsetheight;
if (img.offsetwidth>maxwidth) message+= "R width Excess:" +img.offsetwidth;
if (message!= "") alert (message);
}
</script>
</head>
<body>
<img src= "images/frequency.gif" border=0 id= "IMG1" Onload= "checkimg (this);" >
<br> <input id=inp type= "file" onpropertychange= "Img1.src=this.value;" >
</body>
When the picture is loaded, you can get the picture size successfully, so you want to determine the size of the readystate== "complete"
Test Code Two
<script>
function Qford_getimagesize (filepath)
{
var imgsize={
width:0,
height:0
};
Image=new image ();
Image.src=filepath;
Imgsize.width =image. Width;
Imgsize. height=image. Height;
return imgsize;
}
</script>
JS get picture dimension function test:</br>
<img src= "test.jpg" mce_src= "test.jpg"/>
< Script type= "text/web Effects" ><!--
var a=qford_getimagesize ("Test.jpg");
Alert (' Width: ' +a.width + ' High: ' +a.height ';
</script>