473,796 Members | 2,661 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("sign ed.applets.code base_principal_ support", true);

I've also added this to my java.policy files:

grant codeBase "file:///c:/mywebpagefilesd ir/*" {
permission java.security.A llPermission;
}

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.netscap e && navigator.javaE nabled) {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lFileWrite')
;
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.FileWri ter(fn);
fr.write (txt);
fr.close();
return true;
}
catch(e) {
alert('Permissi on to write to file was denied.');
return false;
}
}
else
return false;
}
else if (document.all) {
var fs = new ActiveXObject(' Scripting.FileS ystemObject');
if (fs.FileExists( fn))
if (!confirm('file ' + fn + ' exists. Overwrite?'))
fn = prompt ('new file name: ', fn);
if (fn) {
var fr = fs.CreateTextFi le (fn, true);
fr.write (txt);
fr.close();
return true;
}
else
return false;
}
}

var fileName = 'c:/mywebpagefilesd ir/test.html';

if (writeToFile(fi leName,
'<html><head>< \/head><body><h2> Hello!<\/h2><\/body><\/html>'))
window.open(fil eName);

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 9433

"Mark Szlazak" <an*******@devd ex.com> wrote in message
news:3f******** *************@n ews.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("sign ed.applets.code base_principal_ support", true);

I've also added this to my java.policy files:

grant codeBase "file:///c:/mywebpagefilesd ir/*" {
permission java.security.A llPermission;
}

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.netscap e && navigator.javaE nabled) {

netscape.securi ty.PrivilegeMan ager.enablePriv ilege('Universa lFileWrite')
;
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.FileWri ter(fn);
fr.write (txt);
fr.close();
return true;
}
catch(e) {
alert('Permissi on to write to file was denied.');
return false;
}
}
else
return false;
}
else if (document.all) {
var fs = new ActiveXObject(' Scripting.FileS ystemObject');
if (fs.FileExists( fn))
if (!confirm('file ' + fn + ' exists. Overwrite?'))
fn = prompt ('new file name: ', fn);
if (fn) {
var fr = fs.CreateTextFi le (fn, true);
fr.write (txt);
fr.close();
return true;
}
else
return false;
}
}

var fileName = 'c:/mywebpagefilesd ir/test.html';

if (writeToFile(fi leName,
'<html><head>< \/head><body><h2> Hello!<\/h2><\/body><\/html>'))
window.open(fil eName);

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(fi lePath, content) {
if (window.netscap e)
try {
netscape.securi ty.PrivilegeMan ager.enablePriv ilege("Universa lXPConnect
");
var file =
Components.clas ses["@mozilla.o rg/file/local;1"].createInstance (Component
s.interfaces.ns ILocalFile);
file.initWithPa th(filePath);
if (!file.exists() ) {
alert('Creating new file ' + filePath);
file.create(0x0 0, 0644);
}
var outputStream =
Components.clas ses["@mozilla.o rg/network/file-output-stream;1"].createIn
stance(Componen ts.interfaces.n sIFileOutputStr eam);
outputStream.in it(file, 0x20 | 0x04, 00004, null);
outputStream.wr ite(content, content.length) ;
outputStream.fl ush();
outputStream.cl ose();
return true;

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

if (xulFileWrite(' D:\\My Web Pages\\test.htm l',
'<html><head>< \/head><body><h2> Hello!<\/h2><\/body><\/html>'))
window.open('fi le:\/\/\/D:\\My Web Pages\\test.htm l', 'testWindow',
'left=20,top=11 0,width=500,hei ght=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
4030
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 explorer-does anyone know how to solve that problem??
7
3026
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* file, not for the *remaining* data to be written. It happens both under 2.3 and 2.2.3. Any ideas?
12
2897
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 series of close mouseovers will cause the screen to go wacko. Does anyone have input on how to get Netscape/Mozilla to work with a fade like this? Thanks!
9
3780
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"> <!-- caption {
6
2358
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 it in action right here: http://www.nicolaizwar.com/whatsthematterwiththis.html The red box on the page is supposed to be in a "fixed" position, though the problem occurs when the position is supposed to be "absolute" as well. Now IE ignores...
4
3153
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
6873
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, blockSize): """write nBlocks*blockSize nuls to a file""" f = open("writeTest.out", "wb") nulBlock = '\0'*blockSize while nBlocks: f.write(nulBlock)
11
2078
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
2408
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, will do after), but not using Netscape, Mozilla (not the FireFox one) and Opera. I've made a test page in which you can see the CSS code, snapshots in
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10236
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7552
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6793
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.