<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>