In IE, activexobject can be used for implementation.
VaR FSO = new activexobject ("scripting. fileSystemObject "); var F1 = FSO. createtextfile ("test.csv", true); f1.writeline ("hello"); f1.writeblanklines (1); // wrap f1.close ();
The relative address can be used here. If you want to know the absolute path of the file, you can use
var ofile=fso.getFile("test.csv"); alert(ofile.path);
Activexobject cannot be used in Firefox. You can implement it in the following ways:
var path = "c:\\test.csv";var content = "Hell0";try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");} catch (e) { alert("no permisson..."); } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile);file.initWithPath(path); if ( file.exists() == false ){ file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream );outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"] .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);converter.charset = 'UTF-8'; var convSource = converter.ConvertFromUnicode(content);var result = outputStream.write( convSource, convSource.length ); outputStream.close();alert("File was saved in "+path);
If the no permisson... window pops up, modify the Firefox config.
Modify method: in the address bar, enter about: config --> Find signed. Applets. codebase_principal_support --> double-click to set the value to true.
The path here specifies an absolute address. If you are interested in using a relative address, you can study it again.