473,499 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File write in Netscape 7 / Mozilla

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_suppo rt", 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!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 9415

"Mark Szlazak" <an*******@devdex.com> wrote in message
news:3f*********************@news.frii.net...
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_suppo rt", 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!

I do not believe you can use Javascript to write to local or server/remote
disk - so I guess the problem you are having is java and not javascript
related hence I suggest you try the java ng.
Jul 20 '05 #2
After looking through Mozilla's xul, javascript and jslib sources, this
is what I got to work.

function xulFileWrite(filePath, content) {
if (window.netscape)
try {
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect
");
var file =
Components.classes["@mozilla.org/file/local;1"].createInstance(Component
s.interfaces.nsILocalFile);
file.initWithPath(filePath);
if (!file.exists()) {
alert('Creating new file ' + filePath);
file.create(0x00, 0644);
}
var outputStream =
Components.classes["@mozilla.org/network/file-output-stream;1"].createIn
stance(Components.interfaces.nsIFileOutputStream);
outputStream.init(file, 0x20 | 0x04, 00004, null);
outputStream.write(content, content.length);
outputStream.flush();
outputStream.close();
return true;

}
catch (e) {
alert(e);
return false;
}
}

if (xulFileWrite('D:\\My Web Pages\\test.html',
'<html><head><\/head><body><h2>Hello!<\/h2><\/body><\/html>'))
window.open('file:\/\/\/D:\\My Web Pages\\test.html', 'testWindow',
'left=20,top=110,width=500,height=200');
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

57
3895
by: Piotr Wolski | last post by:
how to make my page that it was correct with every browser standard? for example when i change HTML's table size it has no effect when i see it under mozilla and has effect under Internet...
7
3014
by: Patrick Useldinger | last post by:
Hi, I think I found a bug in the write method of file objects. It seems as if before writing each block, a check was done in order to verifiy that there is enough space left for the *whole*...
12
2876
by: Joseph Misko | last post by:
I am on WinXP. The following page works perfectly in IE6. For Netscape 7.0, I have to move off of the image and then back on to get the fade to take effect, and with Mozilla (latest version) a...
9
3764
by: Randall Sell | last post by:
Can anyone confirm if I am being an idiot, or is this a bug in the CSS implementation of Netscape 7.x/Mozilla 1.4 ... give the following single HTML: <html> <head> <style type="text/css">...
6
2327
by: Nicolai P. Zwar | last post by:
Hi there, everybody. This here is a sample page of what appears to be a Netscape/Mozilla positioning problem. I posted a the problematic code down at the bottom of this message, and you can see...
4
3123
by: Darren | last post by:
Hi. I have a javascript menu system which uses the "elementFromPoint" function. However Netscape/Mozilla doesn't recognise this function. Does it have an equivilent? Thanks -- Darren
4
6824
by: welch | last post by:
while taking some rough disk performance measures on windows machines, and snooping with FileMon, i've noticed some odd behavior here's the little nul-writer i'm running: def writeTest(nBlocks,...
11
2049
by: A.M | last post by:
Hi, I found print much more flexible that write method. Can I use print instead of file.write method? Thank you,
4
2386
by: Yohan N. Leder | last post by:
Hello all, I have a problem with an horizontal menu which is managed using HTML/CSS combination. All sounds right in most of the major Windows's browsers (not tried until now under Linux,...
0
7178
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.