M
Mark Szlazak
All files that I will be referring to are in the same file folder. I
need my javascipt file to write or save the contents of a textarea to
other local files. This is for local use only on one system.
I have no problem doing this in NN4 and IE.
However, I have problems with nn7 and moz1.4 even when I add this to my
prefs.js files:
user_pref("signed.applets.codebase_principal_support", true);
I've also added this to my java.policy files:
grant codeBase "file:///c:/mywebpagefilesdir/*" {
permission java.security.AllPermission;
}
Here's the javascript code for IE and NN7. I'm always getting the alert
'Permission to write to file was denied.'.
function writeToFile(fn, txt) {
if (window.netscape && navigator.javaEnabled) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalFileWrite')
;
var f = new java.io.File(fn);
if (f.exists())
if (!confirm('file ' + fn + ' exists. Overwrite?'))
fn = prompt ('new file name: ', fn);
if (fn) {
try {
var fr = new java.io.FileWriter(fn);
fr.write (txt);
fr.close();
return true;
}
catch(e) {
alert('Permission to write to file was denied.');
return false;
}
}
else
return false;
}
else if (document.all) {
var fs = new ActiveXObject('Scripting.FileSystemObject');
if (fs.FileExists(fn))
if (!confirm('file ' + fn + ' exists. Overwrite?'))
fn = prompt ('new file name: ', fn);
if (fn) {
var fr = fs.CreateTextFile (fn, true);
fr.write (txt);
fr.close();
return true;
}
else
return false;
}
}
var fileName = 'c:/mywebpagefilesdir/test.html';
if (writeToFile(fileName,
'<html><head><\/head><body><h2>Hello!<\/h2><\/body><\/html>'))
window.open(fileName);
Specific help in making this work would be much appreciated!
need my javascipt file to write or save the contents of a textarea to
other local files. This is for local use only on one system.
I have no problem doing this in NN4 and IE.
However, I have problems with nn7 and moz1.4 even when I add this to my
prefs.js files:
user_pref("signed.applets.codebase_principal_support", true);
I've also added this to my java.policy files:
grant codeBase "file:///c:/mywebpagefilesdir/*" {
permission java.security.AllPermission;
}
Here's the javascript code for IE and NN7. I'm always getting the alert
'Permission to write to file was denied.'.
function writeToFile(fn, txt) {
if (window.netscape && navigator.javaEnabled) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalFileWrite')
;
var f = new java.io.File(fn);
if (f.exists())
if (!confirm('file ' + fn + ' exists. Overwrite?'))
fn = prompt ('new file name: ', fn);
if (fn) {
try {
var fr = new java.io.FileWriter(fn);
fr.write (txt);
fr.close();
return true;
}
catch(e) {
alert('Permission to write to file was denied.');
return false;
}
}
else
return false;
}
else if (document.all) {
var fs = new ActiveXObject('Scripting.FileSystemObject');
if (fs.FileExists(fn))
if (!confirm('file ' + fn + ' exists. Overwrite?'))
fn = prompt ('new file name: ', fn);
if (fn) {
var fr = fs.CreateTextFile (fn, true);
fr.write (txt);
fr.close();
return true;
}
else
return false;
}
}
var fileName = 'c:/mywebpagefilesdir/test.html';
if (writeToFile(fileName,
'<html><head><\/head><body><h2>Hello!<\/h2><\/body><\/html>'))
window.open(fileName);
Specific help in making this work would be much appreciated!