<!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="text/html; charset=gb2312" />
<title>s判断上传图片代码(支持ie8,firefox,ie6)</title>
<script>
function perimg(o)
{var x=document.getelementbyid("upload_file");
var browser_agent=navigator.useragent;
if(browser_agent.indexof("firefox")!=-1)//判断浏览器的类型
{
//火狐
document.getelementbyid("pimg").src = o.files[0].getasdataurl();
document.getelementbyid("pimg").style.display = "block";}
else
{
//ie浏览器
document.getelementbyid('pimg').src =x.value;
}}
function checkimg(){
var maxw=750;
var maxh=750;
var maxs=500;
if (all.img.width>maxw ){
alert("宽度超过"+maxw+"pix,请调整后上传");
}
if (all.img.height>maxh ){
alert("高度超过"+maxh+"pix,请调整后上传");
history.go(0);
}
if (all.img.filesize/1024>maxs ){
alert("大小超过"+maxs+"k,请调整后上传");
history.go(0);
}
}</script>
</head><body>
<div id="perimg" style="display:inline">
<a href="#" id="imghref" target="_blank">
<img border="0" id="pimg">
</a>
</div>
<input name="upload_file" type="file" size="30" onchange="perimg(this);" />实例方法调用
<form name=form action="" method=post enctype=multipart/form-data>
<input type=file name=upload id="img">
<input type=button =提交 onclick="网页特效:checkimg();">
</form></body>
</html>