File control, select files (Pictures, flash, video) immediately preview display _ form effects

Source: Internet
Author: User
We usually use file control to upload files, to preview sometimes refresh the page, the result of the file control is emptied, many people ask can let him not empty or reassign, because in security considerations, this is not possible. So how do I do no refresh preview? Here I write down the method I have used.
Select page:
Copy Code code as follows:

<script language= "JavaScript" >
function Checkdata ()
{
var Filename=document.getelementbyid ("Fileup"). Value;
if (filename== "")
Return
Check file type
var exname=filename.substr (Filename.lastindexof (".") +1). toUpperCase ()
if (exname== "JPG" | | exname== "BMP" | | exname== "GIF")
{
document.getElementById ("Myimg"). Src=filename;
document.getElementById ("Previewimage"). Innerhtml= ' ';
}
Else
if (exname== "SWF")
{
document.getElementById ("Previewimage"). Innerhtml= ' <embed src=\ ' +filename+ ' ' width=\ ' 100\ ' Quality=\ ' high\ ' bgcolor=\ ' #f5f5f5 ' ></embed> ';
}
Else
if (exname== "WMV" | | exname== "MPEG" | | exname== "ASF" | | exname== "AVI")
{
var strcode= ' <embed src=\ ' ' +filename+ ' border=\ ' 0\ ' the ' width=\ ' 100\ ' height=\ ' ' 100\ ' ";
strcode+= ' autostart=\ ' 1\ ' playcount=\ ' 0\ ' enablecontextmenu=\ ' 0\ ' type=\ ' ' application/x-mplayer2\ ' > ';
document.getElementById ("Previewimage"). Innerhtml=strcode;
}
Else
{
Alert ("Please select the correct picture file");
document.getElementById ("Fileup"). value= "";
}
}
function Openwin ()
{
window.open ("addpreview.aspx", "" "," height=300,width=345,top=100,left=100 ");
}
</script>

HTML code:
Copy Code code as follows:

<table border= "0" cellpadding= "0" cellspacing= "0" width= "100%" height= "100%" id= "Table1" >
<tr>
<TD width= "255" height= "100%" valign= "Middle" >
<input id= "Fileup" style= "WIDTH:253PX; height:22px "type=" file "size=" "Name=" File1 "
runat= "Server" onchange= "Checkdata ()" ><br>
Note: This can be a picture (JPG or GIF format), Flash Animation (SWF) and video file (Wmv,mpeg,asf,avi). Size is limited to 1M.
</td>
<td>
<div id= "previewimage" > Current page Preview </div>
</td>
</tr>
</table>

Pop-up Preview page:
Copy Code code as follows:

<script language= "JavaScript" >
function Getstr ()
{
var strcode= "";
var width=100;
var high=100;
if (Self.opener.document.getElementById ("Fileup")!=null)
{
Strcode=self.opener.document.getelementbyid ("Previewimage"). InnerHTML;
Width=self.opener.document.getelementbyid ("Lblwidth"). innertext;
High=self.opener.document.getelementbyid ("Lblhigh"). innertext;
var Filename=self.opener.document.getelementbyid ("Fileup"). Value;
var exname=filename.substr (Filename.lastindexof (".") +1). toUpperCase ()
if (exname== "JPG" | | exname== "BMP" | | exname== "GIF")
{
document.getElementById ("Myimg"). Src=filename;
Strcode= ' ';
}
Else
if (exname== "SWF")
{
Strcode= ' <embed src=\ ' +filename+ ' width=\ ' +width+ ' height=\ ' +high+ ' ' quality=\ ' high\ ' ></embed> ';
}
Else
if (exname== "WMV" | | exname== "MPEG" | | exname== "ASF" | | exname== "AVI")
{
Strcode= ' <embed src=\ ' border=\ ' 0\ ' ' width=\ ' +width+ ' ' height=\ ' +high+ ' ' quality=\ ' high\ ';
strcode+= ' autostart=\ ' 1\ ' playcount=\ ' 0\ ' enablecontextmenu=\ ' 0\ ' type=\ ' ' application/x-mplayer2\ ' > ';
}
}
if (Self.opener.document.getElementById ("Txtadcode")!=null)
{
Strcode=self.opener.document.getelementbyid ("Txtadcode"). InnerHTML;
}
if (strcode!= "")
{
Window.alert (FileName);
document.getElementById ("Showimg"). Innerhtml=strcode;
}
}
</script>

Show:
Copy Code code as follows:

<div id= "Showimg" ></div>

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.