The ability to preview images before uploading them can improve the user experience of your site and make it clear that the images you want to upload are right. This code does not have JS plug-in, pure JavaScript combined with HTML to achieve, is a very good example, relatively complete:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">#preview {width:100px;height:100px;border:1px solid #000; Overflow:hidden;} #imghead {filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (Sizingmethod=image);}</style><script type= "Text/javascript" >functionpreviewimage (file) {varMAXWIDTH = 100; varMaxHeight = 100; vardiv = document.getElementById (' preview '); if(File.files && File.files[0]) {div.innerhtml= ' '; varimg = document.getElementById (' Imghead '); Img.onload=function(){ varRect =Clacimgzoomparam (MAXWIDTH, MaxHeight, Img.offsetwidth, img.offsetheight); Img.width=Rect.width; Img.height=Rect.height; Img.style.marginLeft= rect.left+ ' px '; Img.style.marginTop= rect.top+ ' px '; } varReader =NewFileReader (); Reader.onload=function(EVT) {IMG.SRC =Evt.target.result;} Reader.readasdataurl (file.files[0]); } Else { varSfilter= ' Filter:progid:DXImageTransform.Microsoft.AlphaImageLoader (sizingmethod=scale,src= "'; File.select (); varsrc =Document.selection.createRange (). text; Div.innerhtml= ' '; varimg = document.getElementById (' Imghead '); Img.filters.item (' DXImageTransform.Microsoft.AlphaImageLoader '). src =src; varRect =Clacimgzoomparam (MAXWIDTH, MaxHeight, Img.offsetwidth, img.offsetheight); Status= (' rect: ' +rect.top+ ', ' +rect.left+ ', ' +rect.width+ ', ' +rect.height); Div.innerhtml= "<div id=divhead style= ' width:" +rect.width+ "Px;height:" +rect.height+ "Px;margin-top:" +rect.top+ "PX; Margin-left: "+rect.left+" PX; " +sfilter+src+ "\" ></div> "; }}functionClacimgzoomparam (MaxWidth, maxheight, width, height) {varparam = {top:0, left:0, Width:width, height:height}; if(Width>maxwidth | | height>maxheight) {Ratewidth= width/MaxWidth; Rateheight= height/MaxHeight; if(Ratewidth >rateheight) {Param.width=MaxWidth; Param.height= Math.Round (Height/ratewidth); }Else{param.width= Math.Round (Width/rateheight); Param.height=MaxHeight; }} param.left= Math.Round ((maxwidth-param.width)/2); Param.top= Math.Round ((maxheight-param.height)/2); returnparam;}</script>Compatible JS image upload preview code