Obtain the file input path in different browsers

Source: Internet
Author: User

<Head> <title> file input </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Style>
Body {font-size: 13px ;}
. Box {border: 1px solid # Eee; Background: # FFE; padding: 10px 30px; margin: 10px ;}
Dt {font-weight: bold ;}
DT, IMG, textarea {margin: 8px 0 ;}
Em {color: # f00; font-style: normal ;}
SPAN {color: #999 ;}
. FT {color: #999; font-size: 11px; text-align: right}
</Style>
</Head>
<Body>
<H2> get the value of file input in different browsers </H2>
<Div class = "box">
<Input type = "file" name = "foo" id = "foo" size = "60"/>
<Input type = "button" value = "show value" onclick = "alert (document. getelementbyid ('foo'). Value)"/>
<Input type = "button" value = "show value in ff3" onclick = "alert (getvalueff ('foo')"/>
<Input type = "button" value = "show value in IE8" onclick = "alert (getvalueie8 ('foo')"/>
</Div>
<Div class = "box">
<DL>
<DT> Firefox 2.x, IE6, and IE7 </DT>
<DD> the complete address (including path and file name) can be obtained both locally and remotely. </DD>
</Dl>
<DL>
<DT> firefox 3.0 </DT>
<DD> get the complete address in both local and remote <em> not </em>, but only get the file name </DD>
</Dl>
<DL>
<DT> IE8, IE7 (IE8 simulation) </DT>
<DD> you can obtain the complete address (including the path and file name) locally, <em> not </em> at the remote end, and only the file name </DD>
</Dl>
<Span> * local: localhost </span>
</Div>
<Div class = "box">
<H3> how to obtain the complete path under firefox3 <P>
Step 1: Open the "about: config" Page, find the "signed. Applets. codebase_principal_support" attribute, and set its value to true.
<P> </P>
<P>
Step 2: Use the following code in javascript: <br/>
<Textarea name = "textarea" style = "width: 800px; Height: 300px;">
Function getvalueff (ID ){
VaR IP = Document. getelementbyid (ID );
If (IP. Files ){
// Ffx3-try to have access to full path
Try {
Netscape. Security. privilegemanager. enableprivilege ('universalfileread ')
}
Catch (ERR ){
// Need to set signed. Applets. codebase_principal_support to true
}
};
Return IP. value;
}
</Textarea>
<P> </P>
<P>
After the preceding steps, an Internet security dialog box is displayed when you obtain the value of file input in firefox3. Click "allow" to obtain the complete value. <Br/>
<Span> info: <a href = "https://bugzilla.mozilla.org/show_bug.cgi? Id = 143220 "target =" _ blank "> https://bugzilla.mozilla.org/show_bug.cgi? Id = 143220 </a> </span>
<P> </P>
</Div>
<Div class = "box">
<H3> how to obtain the complete path in IE8 <P> Method 1: use selection. createRange <br/>
<Textarea name = "textarea" style = "width: 800px; Height: 150px;">
Function getvalueie8 (ID ){
VaR IP = Document. getelementbyid (ID );
IP. Select ();
Return document. selection. createRange (). text;
}
</Textarea>
<P> </P>
<P> Method 2: Reference: <a href = "https://bugzilla.mozilla.org/attachment.cgi? Id = 328849 "target =" _ blank "> https://bugzilla.mozilla.org/attachment.cgi? Id = 328849 </a> <p> </P>
</Div>
<Script language = "JavaScript">

Function getvalueff (ID ){
VaR IP = Document. getelementbyid (ID );
If (IP. Files ){
// Ffx3-try to have access to full path
Try {
Netscape. Security. privilegemanager. enableprivilege ('universalfileread ')
}
Catch (ERR ){
// Need to set signed. Applets. codebase_principal_support to true
}
};
Return IP. value;
}
Function getvalueie8 (ID ){
VaR IP = Document. getelementbyid (ID );
IP. Select ();
Return document. selection. createRange (). text;
}
</SCRIPT>
</Body>

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.