JS Upload Image Preview (support Ie7,ie8,firefox)

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax content display document file firefox function html

Web page effects upload picture preview (support Ie7,ie8,firefox)

<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312"/>
<title> Web effects upload picture preview </title>
<script language= "Web Effects" >
function ShowImage (Fileuploadid, Imgid) {
     if (document.getElementById (fileuploadid). Value!= "") {
        document.getElementById (imgid). style.display = "block"
        document.getElementById (imgid). src = GetPath (document.getElementById (Fileuploadid));
   }
 }
 
 function getpath (obj) {
    if (obj) {
         if (Window.navigator.useragent.indexof ("MSIE") >= 1) {
             Obj.select (); Return Document.selection.createrange (). text;
       }
        else if window.Navigator.useragent.indexof ("Firefox") >= 1) {
             if (obj.files) {return Obj.files.item (0). Getasdataurl ();}
            return obj.value;
       }
         return obj.value;
   }
 }

</script>
</head>

<body>
<form enctype= "Multipart/form-data" >
<label>
<input type= "File" name= "file" id= "FID" Onmouseo tutorial ut= "showimage" (' FID ', ' viewimg '); >
</label>
<input name= "" type= "button" value= "Submit" >
</form>
<img src= "" id= "viewimg" >
</div>
</body>
</html>
Code two

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<html>
<head>
<title> New Document </title>
<meta name= "generator" content= "EditPlus" >
<meta name= "Author" content= "" >
<meta name= "keywords" content= "" >
<meta name= "description" content= "" >
<script language= "Web Effects" >
<!--
function showimg (obj) {
var imgobj = document.getElementById ("Imgid");
IMGOBJ.SRC = Obj.value;
}
-->
</script>
</head>

<body>
<input type= "file" onchange= "showimg (This)" ><BR>
<img src= "" id= "Imgid"/>
</body>
</html>
//code three

<html>      
<head>      
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 >      
<title> upload form with picture preview--111cn.net</title>       
<script>      
function Viewmypic (mypic,imgfile) {       
if (imgfile.value) {        
mypic.src=imgfile.value;       
Mypic.style.display= "";       
mypic.border=1;        
}       
}        
</script>      
</head>       
<body>      
<center>      
<form >      
< Input name= "imgfile" type= "file" id= "Imgfile" size= "" onchange= "Viewmypic (showimg,this.form.imgfile);"/>       
<br/>      
</form>       
<img name= "showimg" id= "showimg" src= "style=" Display:none "alt=" "Preview picture"/>       
<br/>      
</div>       
<div style= "Display:none" >      
</div >      
</center>      
</body >      
</html>
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.