It is compatible with IE and Firefox and reads local file JS Code. The author does not provide examples, so only part of the code is available.
<Script type = "text/javascript">
Function read (file ){
If (typeof window. ActiveXObject! = 'Undefined '){
Var content = "";
Try {
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
Var reader = fso. openTextFile (file, 1 );
While (! Reader. AtEndofStream ){
Content + = reader. readline ();
Content + = "\ n ";
}
// Close the reader
Reader. close ();
}
Catch (e ){
Alert ("Internet too e read local file error: \ n" + e );
}
// VeryHuo. Com
Return content;
}
Else if (document. implementation & document. implementation. createDocument ){
Var content = ""
Try {
Netscape. security. PrivilegeManager. enablePrivilege ('universalxpconnect ');
Var lf = Components. classes ["@ mozilla.org/file/local1_1"]. createInstance (Components. interfaces. nsILocalFile );
Lf. initWithPath (file );
If (lf. exists () = false ){
Alert ("File does not exist ");
}
Var FCM = Components. classes ["@ mozilla.org/network/file-input-stream1_1"]. createInstance (Components. interfaces. nsIFileInputStream );
FCM. init (lf, 0x01,000 04, null );
Var sis = Components. classes ["@ mozilla.org/scriptableinputstream1_1"]. createInstance (Components. interfaces. nsIScriptableInputStream );
Sis. init (FCM );
Var converter = Components. classes ["@ mozilla.org/intl/scriptableunicodeconverter"]. createInstance (Components. interfaces. nsIScriptableUnicodeConverter );
Converter. charset = "UTF-8 ";
Content = converter. ConvertToUnicode (sis. read (sis. available ()));
}
Catch (e ){
Alert ("Mozilla Firefox read local file error: \ n" + e );
}
Return content;
}
}
</Script>