<! DOCTYPE HTML Public"-//W3C//DTD XHTML 1.0 transitional//en" "HTTP://WWW.W3.ORG/TR/XHTML1/DTD/XHTML1-TRANSITIONAL.DTD">"Divpreview"> "Imgheadphoto"Src="noperson.jpg"style="width:160px, height:170px, border:solid 1px #d2e2e2;"alt=""/> </div> <input type="file"Onchange="Previewimage (this, ' Imgheadphoto ', ' Divpreview ');"Size=" -"/> <script type="Text/javascript">//JS Local image preview, compatible with ie[6-9], Firefox, chrome17+, opera11+, Maxthon3function Previewimage (fileobj, Imgpreviewid, Divpreviewid) {varAllowextention =". Jpg,.bmp,.gif,.png";//allows the file to be uploaded with the suffix name document.getElementById ("Hfallowpicsuffix"). Value; varextention = fileObj.value.substring (FileObj.value.lastIndexOf (".") +1). toLowerCase (); varBrowserversion =window.navigator.userAgent.toUpperCase (); if(Allowextention.indexof (extention) >-1) { if(fileobj.files) {//HTML5 Implementation Preview, compatible with Chrome, Firefox 7+, etc. if(window. FileReader) {varReader =NewFileReader (); Reader.onload=function (e) {document.getElementById (Imgpreviewid). SetAttribute ("src", E.target.result); } reader.readasdataurl (fileobj.files[0]); } Else if(Browserversion.indexof ("SAFARI") >-1) {alert ("picture preview is not supported Safari6.0 the following browsers!"); } } Else if(Browserversion.indexof ("MSIE") >-1) { if(Browserversion.indexof ("MSIE 6") >-1) {//IE6document.getElementById (Imgpreviewid). SetAttribute ("src", Fileobj.value); } Else{//Ie[7-9]Fileobj.Select(); if(Browserversion.indexof ("MSIE 9") >-1) Fileobj.blur (); //do not add Document.selection.createRange (). Text will be denied access in IE9 varNewpreview = document.getElementById (Divpreviewid +"New"); if(Newpreview = =NULL) {Newpreview= Document.createelement ("Div"); Newpreview.setattribute ("ID", Divpreviewid +"New"); NewPreview.style.width= document.getElementById (imgpreviewid). Width +"px"; NewPreview.style.height= document.getElementById (imgpreviewid). Height +"px"; NewPreview.style.border="Solid 1px #d2e2e2"; } newPreview.style.filter="Progid:DXImageTransform.Microsoft.AlphaImageLoader (sizingmethod= ' scale ', src= '"+ Document.selection.createRange (). Text +"')"; varTempdivpreview =document.getElementById (DIVPREVIEWID); TempDivPreview.parentNode.insertBefore (Newpreview, Tempdivpreview); TempDivPreview.style.display="None"; } } Else if(Browserversion.indexof ("FIREFOX") >-1) {//Firefox varFirefoxversion = parsefloat (Browserversion.tolowercase (). Match (/firefox\/([\d.] +)/)[1]); if(Firefoxversion <7) {//firefox7 The following versionsdocument.getElementById (Imgpreviewid). SetAttribute ("src", fileobj.files[0].getasdataurl ()); } Else{//firefox7.0+document.getElementById (Imgpreviewid). SetAttribute ("src", window. Url.createobjecturl (fileobj.files[0])); } } Else{document.getElementById (imgpreviewid). SetAttribute ("src", Fileobj.value); } } Else{alert ("only support"+ Allowextention +"a file for the suffix name!"); Fileobj.value="";//clear the selected file if(Browserversion.indexof ("MSIE") >-1) {fileobj.Select(); Document.selection.clear (); } fileobj.outerhtml=fileobj.outerhtml; } returnFileobj.value;//return path } </script></body>JS Local image Preview, compatible with ie[6-9], Firefox, chrome17+, opera11+, Maxthon3