473,770 Members | 3,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I write/read local file on hard drive in FireFox (Netscape) ?

Yes you can:

<html><head><sc ript language="javas cript">

SaveToFile('Thi s is a text to save in a file', 'C:\\temp\\test .txt');
alert(read('C:\ \temp\\test.txt '));

function SaveToFile (text, fileName) {
try
{netscape.secur ity.PrivilegeMa nager.enablePri vilege('Univers alXPConnect');}
catch (e) {alert("Permiss ion to write file denied."); return 0;}
var file =
Components.clas ses["@mozilla.o rg/file/local;1"].createInstance (Components.int erfaces.nsILoca lFile);
file.initWithPa th(fileName);
if (!file.exists() ) file.create(0x0 0, 0644);
var outputStream =
Components.clas ses["@mozilla.o rg/network/file-output-stream;1"].createInstance (Components.int erfaces.nsIFile OutputStream);
outputStream.in it(file,0x20 | 0x02,00004,null );
outputStream.wr ite(text, text.length);
outputStream.fl ush();
outputStream.cl ose();
}

function read(myfile) {
try
{netscape.secur ity.PrivilegeMa nager.enablePri vilege("Univers alXPConnect");}
catch (e) {alert("Permiss ion to read file denied."); return '';}
var file =
Components.clas ses["@mozilla.o rg/file/local;1"].createInstance (Components.int erfaces.nsILoca lFile);
file.initWithPa th(myfile);
if (!file.exists() ) {alert("File not found."); return '';}
var is =
Components.clas ses["@mozilla.o rg/network/file-input-stream;1"].createInstance (
Components.inte rfaces.nsIFileI nputStream );
is.init(file,0x 01, 00004, null);
var sis =
Components.clas ses["@mozilla.o rg/scriptableinput stream;1"].createInstance (
Components.inte rfaces.nsIScrip tableInputStrea m );
sis.init(is);
var output = sis.read(sis.av ailable());
return output;
}

</script></head><body></body></html>

Mar 1 '06 #1
2 9550
Alex said the following on 2/28/2006 11:03 PM:
Yes you can:
Yes I can what?

No DTD.
<html><head><sc ript language="javas cript">
Type attribute is mandatory, language attribute is deprecated.
SaveToFile('Thi s is a text to save in a file', 'C:\\temp\\test .txt');
alert(read('C:\ \temp\\test.txt '));

function SaveToFile (text, fileName) {
try
{netscape.secur ity.PrivilegeMa nager.enablePri vilege('Univers alXPConnect');}
catch (e) {alert("Permiss ion to write file denied."); return 0;}


And now, you have not written to my hard drive. Try again :)
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 1 '06 #2
Alex wrote:
Yes you can:


Nobody ever doubted this. In fact, this has been mentioned at least by me
several times before. However, the script needs the privileges, and it
can only get the privileges if it is signed, or, if it is not signed, the
security settings of the client are reduced, which opens a security leak
for all other Web sites.
PointedEars
Mar 1 '06 #3

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

Similar topics

10
6988
by: 3A Web Hosting | last post by:
Hi Folks This is probably starring me in the face but how do I read the contents of a hard drive directory? I've been playing around with the opendir($dir) sample from php.net and can read from the server without problem but how can I read a list of files from the hard drive of the PC (win98 (spit!)) I'm using? Basically what I want to do is read the file names of a certain directory on the hard drive into an array and then upload them...
6
8249
by: chuck clark | last post by:
Hi, I understand that for security and other reasons that javascript does not support writing/reading to text files. I am looking for a way that will however. This is what i am trying to do. I want to develop a simple html page that is run locally on a windows 2000 box in IE. The page will have a browse button to select a source folder, either locally or a network computer on same lan. A destination folder, either locally or a...
20
2009
by: Steve | last post by:
I have a web app that needs to parse through a file that is located on the client machine. I get the file string from a query string & then parse it. It is working fine on my development box but when I put it out on the test server the application is looking for the file on the server & not on the client machine. I am essentially taking the query string & using a stream reader to read the file. I'm sure i'm doing something...
2
2692
by: Trygve Lorentzen | last post by:
Hi, I want to read a file from a http request (say, http://www.foo.com/test.exe) to my local hard drive. How can I do that? I need specific code examples here, not just "use HttpRequest and get a Stream and write that stream to disc with BinaryWriter". This is what I have gotten to so far, it probably looks stupid if you know how to do it, but I can't find much help on the web Uri downloadLoc = new...
23
5383
by: wylbur37 | last post by:
I'm running an Apache server on my own computer (Windows XP Pro). I wrote a simple PHP script (called test3.php) that I'm running by putting the following URL in the address bar of the browser (Firefox) .... http://localhost/test3.php The script generates the following link using the echo statement ...
1
3467
by: demareg | last post by:
When run from local files, my javascript code sets cookies properly and they are visible under the Firefox options. Unfortunately, document.cookie returns an empty string as if cookies are not enabled. The Firefox 'Exceptions - Cookies' menu buttons are not enabled unless a host name is provided so I can't force enable cookies for the local file. The javascript works from local files in IE and from remote files in both IE and Firefox. Does...
2
1848
by: Wanjun Yu | last post by:
What is the class name for open/write/read a text file? I can't find it in the reference book. Thanks! WJ
4
1582
bluegreenisland
by: bluegreenisland | last post by:
Hi everyone, I am new to this, so am bound to make blunders ~just let me know & I'll correct them. I am hoping to learn how to write to a file, make changes to the data, and read. I have a class definition in a .h file, the member functions definitions in a .cpp file, and a driver program which has two functions besides main(): writeFile() and readFile(). My problem is that I don't know what to do now! I tried declaring an object of my...
3
7082
BishoMicho
by: BishoMicho | last post by:
What i want to do is to implement visitor counter in the home page of a web application, with daily visitors and total visitors. i don't want to use code behind, i want to use javascript to write in local file (on server) not on the client side the current number of visitors Can any one help. Best Regads.
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7431
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
5326
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
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2832
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.