faqts : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

95 of 116 people (82%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I open a local file in a window from a http: loaded page?
How can I display a selected file before uploading?

Feb 12th, 2000 17:19
Martin Honnen,


While IE allows a page loaded via http: to open windows with local 
files (i.e. windows with file: urls) NN allows that only to trusted 
scripts. This is particularly important to know for the
  <INPUT TYPE="file">
FORM element where you might want to display a selected file for the 
user before (s)he submits the form.
Here is cross browser code which in the case for NN4 attempts to 
request privilege to display the file. See the faqt on 
  http://www.faqts.com/knowledge-base/view.phtml/aid/840/fid/125/lang/en
  How to run trusted scripts with NN4?
for details how to successfully run such code in your browser. 

<SCRIPT>
function displayLocalFile (fileName) {
  var url = 'file:///' + fileName;
  if (document.layers && location.protocol.toLowerCase() != 'file:' && 
navigator.javaEnabled())
    netscape.security.PrivilegeManager.enablePrivilege
('UniversalFileRead');
  open (url, 'preview');
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="aForm">
<INPUT TYPE="file" NAME="aFile">
<BR>
<INPUT TYPE="BUTTON" VALUE="display file"
       ONCLICK="displayLocalFile(this.form.aFile.value);"
>
</FORM>