Best books about Javasript
|
Detect
image size using Javascript
If you host image gallery business, sometimes you need limit the
uploading image size. You may use the following javascript to check
the image size.
First you may take a look at the following demo.
How
to do it.
Copy the following code to your web page <head></head> section.
<SCRIPT LANGUAGE="JavaScript">
<!--
function imgExceedSize(w,h){
if(!document.form1.image.value==""){
if(img.width>w || img.height>h){
alert("Image size:"+img.width+"X"+img.height+"。Image
too big!Please make it less than "+w+"×"+h);
return true;
}else{
return false;
}
}else{
return true;
}
}
function detect(){
var ok=imgExceedSize(20,20); //20,20 are size limitation
if(ok){
document.form1.reset();
}else{
//success uploading image
document.form1.submit();
}
}
//-->
</SCRIPT> |
You set imgExceedSize(width,height);
to your desired image size. |