How to read and write into file using JavaScript?
Can anybody give some sample code to read and write a file using JavaScript?
javascript file-io
add a comment |
Can anybody give some sample code to read and write a file using JavaScript?
javascript file-io
2
Why do you need it? Maybe there are workarounds.
– Ionuț G. Stan
Feb 25 '09 at 17:22
6
dupe: stackoverflow.com/questions/582268/jquery-read-write-to-file/…
– Paolo Bergantino
Feb 25 '09 at 17:24
1
has been asked many times before in fact
– annakata
Feb 25 '09 at 17:27
1
I found this resource regarding client-side file storage. html5rocks.com/en/tutorials/offline/storage From what I've gathered, HTML5 actually allows Websights to store information on the user's local hard drive, but in a more database-like manor. The browser manages the file storage and imposes certain limits to prevent the World Wide Web from loading peoples hard drives down to the brim. They're not completely fool proof yet, but they're being tweaked, at least according to this article. Have a read for details.
– Garrett
Dec 28 '16 at 3:02
1
Use Ajax and with PHP handle reading and writing files. If you want to handle writing to files client side, you should forget it. It would require many security options to be disabled on the server and you would be left with an extremely insecure site. If you don't want to use PHP, maybe what you want to achieve can be done by using JavaScript Cookies to store data on the clients computer.
– Dan Bray
Jan 14 '17 at 20:24
add a comment |
Can anybody give some sample code to read and write a file using JavaScript?
javascript file-io
Can anybody give some sample code to read and write a file using JavaScript?
javascript file-io
javascript file-io
edited Apr 26 '18 at 0:48
Xufox
10.3k63151
10.3k63151
asked Feb 25 '09 at 9:05
ABC
2
Why do you need it? Maybe there are workarounds.
– Ionuț G. Stan
Feb 25 '09 at 17:22
6
dupe: stackoverflow.com/questions/582268/jquery-read-write-to-file/…
– Paolo Bergantino
Feb 25 '09 at 17:24
1
has been asked many times before in fact
– annakata
Feb 25 '09 at 17:27
1
I found this resource regarding client-side file storage. html5rocks.com/en/tutorials/offline/storage From what I've gathered, HTML5 actually allows Websights to store information on the user's local hard drive, but in a more database-like manor. The browser manages the file storage and imposes certain limits to prevent the World Wide Web from loading peoples hard drives down to the brim. They're not completely fool proof yet, but they're being tweaked, at least according to this article. Have a read for details.
– Garrett
Dec 28 '16 at 3:02
1
Use Ajax and with PHP handle reading and writing files. If you want to handle writing to files client side, you should forget it. It would require many security options to be disabled on the server and you would be left with an extremely insecure site. If you don't want to use PHP, maybe what you want to achieve can be done by using JavaScript Cookies to store data on the clients computer.
– Dan Bray
Jan 14 '17 at 20:24
add a comment |
2
Why do you need it? Maybe there are workarounds.
– Ionuț G. Stan
Feb 25 '09 at 17:22
6
dupe: stackoverflow.com/questions/582268/jquery-read-write-to-file/…
– Paolo Bergantino
Feb 25 '09 at 17:24
1
has been asked many times before in fact
– annakata
Feb 25 '09 at 17:27
1
I found this resource regarding client-side file storage. html5rocks.com/en/tutorials/offline/storage From what I've gathered, HTML5 actually allows Websights to store information on the user's local hard drive, but in a more database-like manor. The browser manages the file storage and imposes certain limits to prevent the World Wide Web from loading peoples hard drives down to the brim. They're not completely fool proof yet, but they're being tweaked, at least according to this article. Have a read for details.
– Garrett
Dec 28 '16 at 3:02
1
Use Ajax and with PHP handle reading and writing files. If you want to handle writing to files client side, you should forget it. It would require many security options to be disabled on the server and you would be left with an extremely insecure site. If you don't want to use PHP, maybe what you want to achieve can be done by using JavaScript Cookies to store data on the clients computer.
– Dan Bray
Jan 14 '17 at 20:24
2
2
Why do you need it? Maybe there are workarounds.
– Ionuț G. Stan
Feb 25 '09 at 17:22
Why do you need it? Maybe there are workarounds.
– Ionuț G. Stan
Feb 25 '09 at 17:22
6
6
dupe: stackoverflow.com/questions/582268/jquery-read-write-to-file/…
– Paolo Bergantino
Feb 25 '09 at 17:24
dupe: stackoverflow.com/questions/582268/jquery-read-write-to-file/…
– Paolo Bergantino
Feb 25 '09 at 17:24
1
1
has been asked many times before in fact
– annakata
Feb 25 '09 at 17:27
has been asked many times before in fact
– annakata
Feb 25 '09 at 17:27
1
1
I found this resource regarding client-side file storage. html5rocks.com/en/tutorials/offline/storage From what I've gathered, HTML5 actually allows Websights to store information on the user's local hard drive, but in a more database-like manor. The browser manages the file storage and imposes certain limits to prevent the World Wide Web from loading peoples hard drives down to the brim. They're not completely fool proof yet, but they're being tweaked, at least according to this article. Have a read for details.
– Garrett
Dec 28 '16 at 3:02
I found this resource regarding client-side file storage. html5rocks.com/en/tutorials/offline/storage From what I've gathered, HTML5 actually allows Websights to store information on the user's local hard drive, but in a more database-like manor. The browser manages the file storage and imposes certain limits to prevent the World Wide Web from loading peoples hard drives down to the brim. They're not completely fool proof yet, but they're being tweaked, at least according to this article. Have a read for details.
– Garrett
Dec 28 '16 at 3:02
1
1
Use Ajax and with PHP handle reading and writing files. If you want to handle writing to files client side, you should forget it. It would require many security options to be disabled on the server and you would be left with an extremely insecure site. If you don't want to use PHP, maybe what you want to achieve can be done by using JavaScript Cookies to store data on the clients computer.
– Dan Bray
Jan 14 '17 at 20:24
Use Ajax and with PHP handle reading and writing files. If you want to handle writing to files client side, you should forget it. It would require many security options to be disabled on the server and you would be left with an extremely insecure site. If you don't want to use PHP, maybe what you want to achieve can be done by using JavaScript Cookies to store data on the clients computer.
– Dan Bray
Jan 14 '17 at 20:24
add a comment |
16 Answers
16
active
oldest
votes
For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)
However javascript per se does allow this; it can be done with server side javascript.
See this documentation on the Javascript File class
Edit: That link was to the Sun docs that now have been moved by Oracle.
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
2
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
1
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
1
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
1
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
add a comment |
No. Browser-side javascript doesn't have permission to write to the client machine without a lot of security options having to be disabled
26
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
42
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
36
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
2
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text isThis answer is not useful.
– Scruffy
Nov 28 '15 at 6:46
2
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
|
show 1 more comment
The future is here! The proposals are closer to completion, no more ActiveX or flash or java. Now we can use:
File System APIs
Native Drag&Drop File Access
You could use the Drag/Drop to get the file into the browser, or a simple upload control. Once the user has selected a file, you can read it w/ Javascript: http://www.html5rocks.com/en/tutorials/file/dndfiles/
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
1
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
1
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
add a comment |
here's the mozilla proposal
http://www-archive.mozilla.org/js/js-file-object.html
this is implemented with a compilation switch in spidermonkey, and also in adobe's extendscript. Additionally (I think) you get the File object in firefox extensions.
rhino has a (rather rudementary) readFile function
https://developer.mozilla.org/en/Rhino_Shell
for more complex file operations in rhino, you can use java.io.File methods.
you won't get any of this stuff in the browser though. For similar functionality in a browser you can use the SQL database functions from HTML5, clientside persistence, cookies, and flash storage objects.
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
add a comment |
This Javascript function presents a complete "Save As" Dialog box to the user who runs this through the browser. The user presses OK and the file is saved.
Edit: The following code only works with IE Browser since Firefox and Chrome have considered this code a security problem and has blocked it from working.
// content is the data you'll write to file<br/>
// filename is the filename<br/>
// what I did is use iFrame as a buffer, fill it up with text
function save_content_to_file(content, filename)
var dlg = false;
with(document)
ir=createElement('iframe');
ir.id='ifr';
ir.location='about.blank';
ir.style.display='none';
body.appendChild(ir);
with(getElementById('ifr').contentWindow.document)
open("text/plain", "replace");
charset = "utf-8";
write(content);
close();
document.charset = "utf-8";
dlg = execCommand('SaveAs', false, filename+'.txt');
body.removeChild(ir);
return dlg;
Invoke the function:
save_content_to_file("Hello", "C:\test");
1
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
4
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
add a comment |
If you are using JScript (Microsoft's Javascript) to do local scripting using WSH (NOT in a browser!) you can use Scripting.FileSystemObject to access the file system.
I think you can access that same object in IE if you turn a lot of security settings off, but that would be a very, very bad idea.
MSDN here
I wanted to do this in anhtaapplication and that solves it
– chiliNUT
Dec 14 '15 at 22:58
add a comment |
For Firefox:
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");
See https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O
For others, check out the TiddlyWiki app to see how it does it.
add a comment |
Currently, files can be written and read from the context of a browser tab/window with the File, FileWriter, and FileSystem APIs, though there are caveats to their use (see tail of this answer).
But to answer your question:
Using BakedGoods*
Write file:
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
Read file:
bakedGoods.get(
data: ["testFile"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(resultDataObj, byStorageTypeErrorObj)
);
Using the raw File, FileWriter, and FileSystem APIs
Write file:
function onQuotaRequestSuccess(grantedQuota)
function saveFile(directoryEntry)
function createFileWriter(fileEntry)
function write(fileWriter)
var dataBlob = new Blob(["Hello world!"], type: "text/plain");
fileWriter.write(dataBlob);
fileEntry.createWriter(write);
directoryEntry.getFile(
"testFile",
create: true, exclusive: true,
createFileWriter
);
requestFileSystem(Window.PERSISTENT, grantedQuota, saveFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Read file:
function onQuotaRequestSuccess(grantedQuota)
function getfile(directoryEntry)
function readFile(fileEntry)
function read(file)
var fileReader = new FileReader();
fileReader.onload = function()var fileData = fileReader.result;
fileReader.readAsText(file);
fileEntry.file(read);
directoryEntry.getFile(
"testFile",
create: false,
readFile
);
requestFileSystem(Window.PERSISTENT, grantedQuota, getFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Just what you asked for right? Maybe, maybe not. The latter two of the APIs:
- Are currently only implemented in Chromium-based browsers (Chrome & Opera)
- Have been taken off the W3C standards track, and as of now are proprietary APIs
- May be removed from the implementing browsers in the future
- Constrict the creation of files to a sandbox (a location outside of which the files can produce no effect) on disk
Additionally, the FileSystem spec defines no guidelines on how directory structures are to appear on disk. In Chromium-based browsers for example, the sandbox has a virtual file system (a directory structure which does not necessarily exist on disk in the same form that it does when accessed from within the browser), within which the directories and files created with the APIs are placed.
So though you may be able to write files to a system with the APIs, locating the files without the APIs (well, without the FileSystem API) could be a non-trivial affair.
If you can deal with these issues/limitations, these APIs are pretty much the only native way to do what you've asked.
If you're open to non-native solutions, Silverlight also allows for file i/o from a tab/window contest through IsolatedStorage. However, managed code is required to utilize this facility; a solution which requires writing such code is beyond the scope of this question.
Of course, a solution which makes use of complementary managed code, leaving one with only Javascript to write, is well within the scope of this question ;) :
//Write file to first of either FileSystem or IsolatedStorage
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem", "silverlight"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
* BakedGoods is a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities. It is maintained by this guy right here : ) .
add a comment |
In the context of browser, Javascript can READ user-specified file. See Eric Bidelman's blog for detail about reading file using File API.
However, it is not possible for browser-based Javascript to WRITE the file system of local computer without disabling some security settings because it is regarded as a security threat for any website to change your local file system arbitrarily.
Saying that, there are some ways to work around it depending what you are trying to do:
If it is your own site, you can embed a Java Applet in the web page. However, the visitor has to install Java on local machine and will be alerted about the security risk. The visitor has to allow the applet to be loaded. An Java Applet is like an executable software that has complete access to the local computer.
Chrome supports a file system which is a sandboxed portion of the local file system. See this page for details. This provides possibly for you to temporarily save things locally. However, this is not supported by other browsers.
If you are not limited to browser, Node.js has a complete file system interface. See here for its file system documentation. Note that Node.js can run not only on servers, but also any client computer including windows. The javascript test runner Karma is based on Node.js. If you just like to program in javascript on the local computer, this is an option.
add a comment |
You'll have to turn to Flash, Java or Silverlight. In the case of Silverlight, you'll be looking at Isolated Storage. That will get you write to files in your own playground on the users disk. It won't let you write outside of your playground though.
add a comment |
To create file try
function makefile()
var fso;
var thefile;
fso = new ActiveXObject("Scripting.FileSystemObject");
thefile=fso.CreateTextFile("C:\tmp\MyFile.txt",true);
thefile.close()
Create your directory in the C drive because windows has security against writing from web
e.g create folder named "tmp" in C drive.
2
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
add a comment |
You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write files, but that is it unfortunately.
If you are looking to save user information, you will most likely need to use cookies.
4
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
add a comment |
From a ReactJS test, the following code successfully writes a file:
import writeJsonFile from 'write-json-file';
const ans = 42;
writeJsonFile('answer.txt', ans);
const json = "answer": ans;
writeJsonFile('answer_json.txt', json);
The file is written to the directory containing the tests, so writing to an actual JSON file '*.json' creates a loop!
add a comment |
You cannot do file i/o on the client side using javascript as that would be a security risk. You'd either have to get them to download and run an exe, or if the file is on your server, use AJAX and a server-side language such as PHP to do the i/o on serverside
1
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
add a comment |
There are two ways to read and write a file using JavaScript
Using JavaScript extensions
Using a web page and Active X objects
add a comment |
Here is write solution for chrome v52+ (user still need to select a destination doe...)
source: StreamSaver.js
<!-- load StreamSaver.js before streams polyfill to detect support -->
<script src="StreamSaver.js"></script>
<script src="https://wzrd.in/standalone/web-streams-polyfill@latest"></script>
const writeStream = streamSaver.createWriteStream('filename.txt')
const encoder = new TextEncoder
let data = 'a'.repeat(1024)
let uint8array = encoder.encode(data + "nn")
writeStream.write(uint8array) // must be uInt8array
writeStream.close()
Best suited for writing large data generated on client side.
Otherwise I suggest using FileSaver.js to save Blob/Files
add a comment |
protected by Community♦ Nov 13 '14 at 22:08
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
16 Answers
16
active
oldest
votes
16 Answers
16
active
oldest
votes
active
oldest
votes
active
oldest
votes
For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)
However javascript per se does allow this; it can be done with server side javascript.
See this documentation on the Javascript File class
Edit: That link was to the Sun docs that now have been moved by Oracle.
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
2
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
1
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
1
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
1
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
add a comment |
For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)
However javascript per se does allow this; it can be done with server side javascript.
See this documentation on the Javascript File class
Edit: That link was to the Sun docs that now have been moved by Oracle.
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
2
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
1
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
1
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
1
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
add a comment |
For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)
However javascript per se does allow this; it can be done with server side javascript.
See this documentation on the Javascript File class
Edit: That link was to the Sun docs that now have been moved by Oracle.
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)
However javascript per se does allow this; it can be done with server side javascript.
See this documentation on the Javascript File class
Edit: That link was to the Sun docs that now have been moved by Oracle.
To keep up with the times here's the node.js documentation for the FileSystem class: http://nodejs.org/docs/latest/api/fs.html
Edit(2): You can read files client side now with HTML5: http://www.html5rocks.com/en/tutorials/file/dndfiles/
edited Nov 22 '13 at 8:50
answered Feb 25 '09 at 17:26
DanSingermanDanSingerman
26k107287
26k107287
2
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
1
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
1
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
1
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
add a comment |
2
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
1
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
1
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
1
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
2
2
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
Is it possible to write to local files using HTML5 as well?
– Anderson Green
Aug 3 '12 at 17:43
1
1
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
@AndersonGreen - No.
– Rob
Sep 24 '12 at 19:32
1
1
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
Also, depending on your situation you could make an ajax call to a php script and dump the data that way. This was useful in my situation where I wanted to store some data generated on the javascript side, but didn't matter how it got there.
– Dustin Graham
Jan 15 '13 at 2:34
1
1
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
@DustinGraham, Actually now with Chrome APIs we can actually write files to client side via JavaScript right?
– Pacerier
Jun 26 '15 at 23:35
add a comment |
No. Browser-side javascript doesn't have permission to write to the client machine without a lot of security options having to be disabled
26
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
42
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
36
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
2
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text isThis answer is not useful.
– Scruffy
Nov 28 '15 at 6:46
2
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
|
show 1 more comment
No. Browser-side javascript doesn't have permission to write to the client machine without a lot of security options having to be disabled
26
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
42
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
36
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
2
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text isThis answer is not useful.
– Scruffy
Nov 28 '15 at 6:46
2
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
|
show 1 more comment
No. Browser-side javascript doesn't have permission to write to the client machine without a lot of security options having to be disabled
No. Browser-side javascript doesn't have permission to write to the client machine without a lot of security options having to be disabled
answered Feb 25 '09 at 9:08
GarethGareth
91.9k29136149
91.9k29136149
26
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
42
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
36
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
2
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text isThis answer is not useful.
– Scruffy
Nov 28 '15 at 6:46
2
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
|
show 1 more comment
26
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
42
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
36
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
2
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text isThis answer is not useful.
– Scruffy
Nov 28 '15 at 6:46
2
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
26
26
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
-1, OP never said anything about browser-side
– marcgg
Jan 10 '11 at 15:09
42
42
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
@marcgg: That makes this answer incomplete, not incorrect. And, let's face it, it's highly likely that this answer does cover the OP's use case.
– Lightness Races in Orbit
Jun 8 '11 at 12:16
36
36
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
If the OP was planning on using javascript outside of the browser, that's uncommon enough that they probably would have mentioned it. It's not unreasonable (and definitely not incorrect) to assume a browser. +1 (to make up for marcgg's -1).
– Michael Martin-Smucker
Jun 15 '11 at 12:26
2
2
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text is
This answer is not useful.– Scruffy
Nov 28 '15 at 6:46
@LightnessRacesinOrbit The downvote button doesn't mean that the answer is thought to be incorrect. Its tooltip text is
This answer is not useful.– Scruffy
Nov 28 '15 at 6:46
2
2
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
node.js is HUGE now.
– Mike
Jan 28 '16 at 19:53
|
show 1 more comment
The future is here! The proposals are closer to completion, no more ActiveX or flash or java. Now we can use:
File System APIs
Native Drag&Drop File Access
You could use the Drag/Drop to get the file into the browser, or a simple upload control. Once the user has selected a file, you can read it w/ Javascript: http://www.html5rocks.com/en/tutorials/file/dndfiles/
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
1
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
1
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
add a comment |
The future is here! The proposals are closer to completion, no more ActiveX or flash or java. Now we can use:
File System APIs
Native Drag&Drop File Access
You could use the Drag/Drop to get the file into the browser, or a simple upload control. Once the user has selected a file, you can read it w/ Javascript: http://www.html5rocks.com/en/tutorials/file/dndfiles/
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
1
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
1
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
add a comment |
The future is here! The proposals are closer to completion, no more ActiveX or flash or java. Now we can use:
File System APIs
Native Drag&Drop File Access
You could use the Drag/Drop to get the file into the browser, or a simple upload control. Once the user has selected a file, you can read it w/ Javascript: http://www.html5rocks.com/en/tutorials/file/dndfiles/
The future is here! The proposals are closer to completion, no more ActiveX or flash or java. Now we can use:
File System APIs
Native Drag&Drop File Access
You could use the Drag/Drop to get the file into the browser, or a simple upload control. Once the user has selected a file, you can read it w/ Javascript: http://www.html5rocks.com/en/tutorials/file/dndfiles/
edited Jan 17 at 0:36
answered Aug 10 '11 at 12:55
Thomas ShieldsThomas Shields
7,79853475
7,79853475
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
1
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
1
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
add a comment |
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
1
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
1
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
Links are broken now.
– Prometheus
Jun 28 '16 at 7:38
1
1
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
@Prometheus fixed to link to MDN docs
– Thomas Shields
Jun 28 '16 at 18:22
1
1
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Yeap, working now. Thanks @Thomas
– Prometheus
Jun 29 '16 at 11:30
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
Links are broken again, they're both the same link, but with different meanings.. Broken.
– insidesin
Dec 12 '18 at 4:43
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
@insidesin fixed
– Thomas Shields
Jan 17 at 0:36
add a comment |
here's the mozilla proposal
http://www-archive.mozilla.org/js/js-file-object.html
this is implemented with a compilation switch in spidermonkey, and also in adobe's extendscript. Additionally (I think) you get the File object in firefox extensions.
rhino has a (rather rudementary) readFile function
https://developer.mozilla.org/en/Rhino_Shell
for more complex file operations in rhino, you can use java.io.File methods.
you won't get any of this stuff in the browser though. For similar functionality in a browser you can use the SQL database functions from HTML5, clientside persistence, cookies, and flash storage objects.
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
add a comment |
here's the mozilla proposal
http://www-archive.mozilla.org/js/js-file-object.html
this is implemented with a compilation switch in spidermonkey, and also in adobe's extendscript. Additionally (I think) you get the File object in firefox extensions.
rhino has a (rather rudementary) readFile function
https://developer.mozilla.org/en/Rhino_Shell
for more complex file operations in rhino, you can use java.io.File methods.
you won't get any of this stuff in the browser though. For similar functionality in a browser you can use the SQL database functions from HTML5, clientside persistence, cookies, and flash storage objects.
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
add a comment |
here's the mozilla proposal
http://www-archive.mozilla.org/js/js-file-object.html
this is implemented with a compilation switch in spidermonkey, and also in adobe's extendscript. Additionally (I think) you get the File object in firefox extensions.
rhino has a (rather rudementary) readFile function
https://developer.mozilla.org/en/Rhino_Shell
for more complex file operations in rhino, you can use java.io.File methods.
you won't get any of this stuff in the browser though. For similar functionality in a browser you can use the SQL database functions from HTML5, clientside persistence, cookies, and flash storage objects.
here's the mozilla proposal
http://www-archive.mozilla.org/js/js-file-object.html
this is implemented with a compilation switch in spidermonkey, and also in adobe's extendscript. Additionally (I think) you get the File object in firefox extensions.
rhino has a (rather rudementary) readFile function
https://developer.mozilla.org/en/Rhino_Shell
for more complex file operations in rhino, you can use java.io.File methods.
you won't get any of this stuff in the browser though. For similar functionality in a browser you can use the SQL database functions from HTML5, clientside persistence, cookies, and flash storage objects.
edited Apr 17 '12 at 4:57
answered Feb 25 '09 at 9:59
BretonBreton
12.8k24972
12.8k24972
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
add a comment |
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
the link that you have mentioned is broken..
– R K
Apr 4 '12 at 17:51
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
@radkrish fixed it.
– Breton
Apr 17 '12 at 4:57
add a comment |
This Javascript function presents a complete "Save As" Dialog box to the user who runs this through the browser. The user presses OK and the file is saved.
Edit: The following code only works with IE Browser since Firefox and Chrome have considered this code a security problem and has blocked it from working.
// content is the data you'll write to file<br/>
// filename is the filename<br/>
// what I did is use iFrame as a buffer, fill it up with text
function save_content_to_file(content, filename)
var dlg = false;
with(document)
ir=createElement('iframe');
ir.id='ifr';
ir.location='about.blank';
ir.style.display='none';
body.appendChild(ir);
with(getElementById('ifr').contentWindow.document)
open("text/plain", "replace");
charset = "utf-8";
write(content);
close();
document.charset = "utf-8";
dlg = execCommand('SaveAs', false, filename+'.txt');
body.removeChild(ir);
return dlg;
Invoke the function:
save_content_to_file("Hello", "C:\test");
1
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
4
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
add a comment |
This Javascript function presents a complete "Save As" Dialog box to the user who runs this through the browser. The user presses OK and the file is saved.
Edit: The following code only works with IE Browser since Firefox and Chrome have considered this code a security problem and has blocked it from working.
// content is the data you'll write to file<br/>
// filename is the filename<br/>
// what I did is use iFrame as a buffer, fill it up with text
function save_content_to_file(content, filename)
var dlg = false;
with(document)
ir=createElement('iframe');
ir.id='ifr';
ir.location='about.blank';
ir.style.display='none';
body.appendChild(ir);
with(getElementById('ifr').contentWindow.document)
open("text/plain", "replace");
charset = "utf-8";
write(content);
close();
document.charset = "utf-8";
dlg = execCommand('SaveAs', false, filename+'.txt');
body.removeChild(ir);
return dlg;
Invoke the function:
save_content_to_file("Hello", "C:\test");
1
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
4
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
add a comment |
This Javascript function presents a complete "Save As" Dialog box to the user who runs this through the browser. The user presses OK and the file is saved.
Edit: The following code only works with IE Browser since Firefox and Chrome have considered this code a security problem and has blocked it from working.
// content is the data you'll write to file<br/>
// filename is the filename<br/>
// what I did is use iFrame as a buffer, fill it up with text
function save_content_to_file(content, filename)
var dlg = false;
with(document)
ir=createElement('iframe');
ir.id='ifr';
ir.location='about.blank';
ir.style.display='none';
body.appendChild(ir);
with(getElementById('ifr').contentWindow.document)
open("text/plain", "replace");
charset = "utf-8";
write(content);
close();
document.charset = "utf-8";
dlg = execCommand('SaveAs', false, filename+'.txt');
body.removeChild(ir);
return dlg;
Invoke the function:
save_content_to_file("Hello", "C:\test");
This Javascript function presents a complete "Save As" Dialog box to the user who runs this through the browser. The user presses OK and the file is saved.
Edit: The following code only works with IE Browser since Firefox and Chrome have considered this code a security problem and has blocked it from working.
// content is the data you'll write to file<br/>
// filename is the filename<br/>
// what I did is use iFrame as a buffer, fill it up with text
function save_content_to_file(content, filename)
var dlg = false;
with(document)
ir=createElement('iframe');
ir.id='ifr';
ir.location='about.blank';
ir.style.display='none';
body.appendChild(ir);
with(getElementById('ifr').contentWindow.document)
open("text/plain", "replace");
charset = "utf-8";
write(content);
close();
document.charset = "utf-8";
dlg = execCommand('SaveAs', false, filename+'.txt');
body.removeChild(ir);
return dlg;
Invoke the function:
save_content_to_file("Hello", "C:\test");
edited Feb 13 '13 at 14:19
Eric Leschinski
89.4k40329281
89.4k40329281
answered Oct 24 '11 at 8:34
TempTemp
235615
235615
1
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
4
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
add a comment |
1
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
4
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
1
1
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
ir=createElement('iframe'); -- iframe is iFrame ID.
– Temp
Oct 24 '11 at 8:35
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Sample code above is just for writing...
– Temp
Oct 24 '11 at 8:38
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Will this code sample work in all web browsers?
– Anderson Green
Aug 3 '12 at 17:45
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
Also, will it work on all operating systems (as long as a valid file location is chosen?)
– Anderson Green
Aug 3 '12 at 17:51
4
4
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
This is a good solution but, does it work with only IE? I tried IE and FF and with FF it does not work.
– u.gen
Oct 26 '12 at 14:03
add a comment |
If you are using JScript (Microsoft's Javascript) to do local scripting using WSH (NOT in a browser!) you can use Scripting.FileSystemObject to access the file system.
I think you can access that same object in IE if you turn a lot of security settings off, but that would be a very, very bad idea.
MSDN here
I wanted to do this in anhtaapplication and that solves it
– chiliNUT
Dec 14 '15 at 22:58
add a comment |
If you are using JScript (Microsoft's Javascript) to do local scripting using WSH (NOT in a browser!) you can use Scripting.FileSystemObject to access the file system.
I think you can access that same object in IE if you turn a lot of security settings off, but that would be a very, very bad idea.
MSDN here
I wanted to do this in anhtaapplication and that solves it
– chiliNUT
Dec 14 '15 at 22:58
add a comment |
If you are using JScript (Microsoft's Javascript) to do local scripting using WSH (NOT in a browser!) you can use Scripting.FileSystemObject to access the file system.
I think you can access that same object in IE if you turn a lot of security settings off, but that would be a very, very bad idea.
MSDN here
If you are using JScript (Microsoft's Javascript) to do local scripting using WSH (NOT in a browser!) you can use Scripting.FileSystemObject to access the file system.
I think you can access that same object in IE if you turn a lot of security settings off, but that would be a very, very bad idea.
MSDN here
answered Feb 25 '09 at 9:17
Dana RobinsonDana Robinson
2,60772638
2,60772638
I wanted to do this in anhtaapplication and that solves it
– chiliNUT
Dec 14 '15 at 22:58
add a comment |
I wanted to do this in anhtaapplication and that solves it
– chiliNUT
Dec 14 '15 at 22:58
I wanted to do this in an
hta application and that solves it– chiliNUT
Dec 14 '15 at 22:58
I wanted to do this in an
hta application and that solves it– chiliNUT
Dec 14 '15 at 22:58
add a comment |
For Firefox:
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");
See https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O
For others, check out the TiddlyWiki app to see how it does it.
add a comment |
For Firefox:
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");
See https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O
For others, check out the TiddlyWiki app to see how it does it.
add a comment |
For Firefox:
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");
See https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O
For others, check out the TiddlyWiki app to see how it does it.
For Firefox:
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("/home");
See https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O
For others, check out the TiddlyWiki app to see how it does it.
edited Nov 13 '13 at 17:41
MarkDBlackwell
9611021
9611021
answered Feb 2 '12 at 20:28
Lindsay MorsilloLindsay Morsillo
470618
470618
add a comment |
add a comment |
Currently, files can be written and read from the context of a browser tab/window with the File, FileWriter, and FileSystem APIs, though there are caveats to their use (see tail of this answer).
But to answer your question:
Using BakedGoods*
Write file:
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
Read file:
bakedGoods.get(
data: ["testFile"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(resultDataObj, byStorageTypeErrorObj)
);
Using the raw File, FileWriter, and FileSystem APIs
Write file:
function onQuotaRequestSuccess(grantedQuota)
function saveFile(directoryEntry)
function createFileWriter(fileEntry)
function write(fileWriter)
var dataBlob = new Blob(["Hello world!"], type: "text/plain");
fileWriter.write(dataBlob);
fileEntry.createWriter(write);
directoryEntry.getFile(
"testFile",
create: true, exclusive: true,
createFileWriter
);
requestFileSystem(Window.PERSISTENT, grantedQuota, saveFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Read file:
function onQuotaRequestSuccess(grantedQuota)
function getfile(directoryEntry)
function readFile(fileEntry)
function read(file)
var fileReader = new FileReader();
fileReader.onload = function()var fileData = fileReader.result;
fileReader.readAsText(file);
fileEntry.file(read);
directoryEntry.getFile(
"testFile",
create: false,
readFile
);
requestFileSystem(Window.PERSISTENT, grantedQuota, getFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Just what you asked for right? Maybe, maybe not. The latter two of the APIs:
- Are currently only implemented in Chromium-based browsers (Chrome & Opera)
- Have been taken off the W3C standards track, and as of now are proprietary APIs
- May be removed from the implementing browsers in the future
- Constrict the creation of files to a sandbox (a location outside of which the files can produce no effect) on disk
Additionally, the FileSystem spec defines no guidelines on how directory structures are to appear on disk. In Chromium-based browsers for example, the sandbox has a virtual file system (a directory structure which does not necessarily exist on disk in the same form that it does when accessed from within the browser), within which the directories and files created with the APIs are placed.
So though you may be able to write files to a system with the APIs, locating the files without the APIs (well, without the FileSystem API) could be a non-trivial affair.
If you can deal with these issues/limitations, these APIs are pretty much the only native way to do what you've asked.
If you're open to non-native solutions, Silverlight also allows for file i/o from a tab/window contest through IsolatedStorage. However, managed code is required to utilize this facility; a solution which requires writing such code is beyond the scope of this question.
Of course, a solution which makes use of complementary managed code, leaving one with only Javascript to write, is well within the scope of this question ;) :
//Write file to first of either FileSystem or IsolatedStorage
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem", "silverlight"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
* BakedGoods is a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities. It is maintained by this guy right here : ) .
add a comment |
Currently, files can be written and read from the context of a browser tab/window with the File, FileWriter, and FileSystem APIs, though there are caveats to their use (see tail of this answer).
But to answer your question:
Using BakedGoods*
Write file:
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
Read file:
bakedGoods.get(
data: ["testFile"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(resultDataObj, byStorageTypeErrorObj)
);
Using the raw File, FileWriter, and FileSystem APIs
Write file:
function onQuotaRequestSuccess(grantedQuota)
function saveFile(directoryEntry)
function createFileWriter(fileEntry)
function write(fileWriter)
var dataBlob = new Blob(["Hello world!"], type: "text/plain");
fileWriter.write(dataBlob);
fileEntry.createWriter(write);
directoryEntry.getFile(
"testFile",
create: true, exclusive: true,
createFileWriter
);
requestFileSystem(Window.PERSISTENT, grantedQuota, saveFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Read file:
function onQuotaRequestSuccess(grantedQuota)
function getfile(directoryEntry)
function readFile(fileEntry)
function read(file)
var fileReader = new FileReader();
fileReader.onload = function()var fileData = fileReader.result;
fileReader.readAsText(file);
fileEntry.file(read);
directoryEntry.getFile(
"testFile",
create: false,
readFile
);
requestFileSystem(Window.PERSISTENT, grantedQuota, getFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Just what you asked for right? Maybe, maybe not. The latter two of the APIs:
- Are currently only implemented in Chromium-based browsers (Chrome & Opera)
- Have been taken off the W3C standards track, and as of now are proprietary APIs
- May be removed from the implementing browsers in the future
- Constrict the creation of files to a sandbox (a location outside of which the files can produce no effect) on disk
Additionally, the FileSystem spec defines no guidelines on how directory structures are to appear on disk. In Chromium-based browsers for example, the sandbox has a virtual file system (a directory structure which does not necessarily exist on disk in the same form that it does when accessed from within the browser), within which the directories and files created with the APIs are placed.
So though you may be able to write files to a system with the APIs, locating the files without the APIs (well, without the FileSystem API) could be a non-trivial affair.
If you can deal with these issues/limitations, these APIs are pretty much the only native way to do what you've asked.
If you're open to non-native solutions, Silverlight also allows for file i/o from a tab/window contest through IsolatedStorage. However, managed code is required to utilize this facility; a solution which requires writing such code is beyond the scope of this question.
Of course, a solution which makes use of complementary managed code, leaving one with only Javascript to write, is well within the scope of this question ;) :
//Write file to first of either FileSystem or IsolatedStorage
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem", "silverlight"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
* BakedGoods is a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities. It is maintained by this guy right here : ) .
add a comment |
Currently, files can be written and read from the context of a browser tab/window with the File, FileWriter, and FileSystem APIs, though there are caveats to their use (see tail of this answer).
But to answer your question:
Using BakedGoods*
Write file:
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
Read file:
bakedGoods.get(
data: ["testFile"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(resultDataObj, byStorageTypeErrorObj)
);
Using the raw File, FileWriter, and FileSystem APIs
Write file:
function onQuotaRequestSuccess(grantedQuota)
function saveFile(directoryEntry)
function createFileWriter(fileEntry)
function write(fileWriter)
var dataBlob = new Blob(["Hello world!"], type: "text/plain");
fileWriter.write(dataBlob);
fileEntry.createWriter(write);
directoryEntry.getFile(
"testFile",
create: true, exclusive: true,
createFileWriter
);
requestFileSystem(Window.PERSISTENT, grantedQuota, saveFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Read file:
function onQuotaRequestSuccess(grantedQuota)
function getfile(directoryEntry)
function readFile(fileEntry)
function read(file)
var fileReader = new FileReader();
fileReader.onload = function()var fileData = fileReader.result;
fileReader.readAsText(file);
fileEntry.file(read);
directoryEntry.getFile(
"testFile",
create: false,
readFile
);
requestFileSystem(Window.PERSISTENT, grantedQuota, getFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Just what you asked for right? Maybe, maybe not. The latter two of the APIs:
- Are currently only implemented in Chromium-based browsers (Chrome & Opera)
- Have been taken off the W3C standards track, and as of now are proprietary APIs
- May be removed from the implementing browsers in the future
- Constrict the creation of files to a sandbox (a location outside of which the files can produce no effect) on disk
Additionally, the FileSystem spec defines no guidelines on how directory structures are to appear on disk. In Chromium-based browsers for example, the sandbox has a virtual file system (a directory structure which does not necessarily exist on disk in the same form that it does when accessed from within the browser), within which the directories and files created with the APIs are placed.
So though you may be able to write files to a system with the APIs, locating the files without the APIs (well, without the FileSystem API) could be a non-trivial affair.
If you can deal with these issues/limitations, these APIs are pretty much the only native way to do what you've asked.
If you're open to non-native solutions, Silverlight also allows for file i/o from a tab/window contest through IsolatedStorage. However, managed code is required to utilize this facility; a solution which requires writing such code is beyond the scope of this question.
Of course, a solution which makes use of complementary managed code, leaving one with only Javascript to write, is well within the scope of this question ;) :
//Write file to first of either FileSystem or IsolatedStorage
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem", "silverlight"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
* BakedGoods is a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities. It is maintained by this guy right here : ) .
Currently, files can be written and read from the context of a browser tab/window with the File, FileWriter, and FileSystem APIs, though there are caveats to their use (see tail of this answer).
But to answer your question:
Using BakedGoods*
Write file:
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
Read file:
bakedGoods.get(
data: ["testFile"],
storageTypes: ["fileSystem"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(resultDataObj, byStorageTypeErrorObj)
);
Using the raw File, FileWriter, and FileSystem APIs
Write file:
function onQuotaRequestSuccess(grantedQuota)
function saveFile(directoryEntry)
function createFileWriter(fileEntry)
function write(fileWriter)
var dataBlob = new Blob(["Hello world!"], type: "text/plain");
fileWriter.write(dataBlob);
fileEntry.createWriter(write);
directoryEntry.getFile(
"testFile",
create: true, exclusive: true,
createFileWriter
);
requestFileSystem(Window.PERSISTENT, grantedQuota, saveFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Read file:
function onQuotaRequestSuccess(grantedQuota)
function getfile(directoryEntry)
function readFile(fileEntry)
function read(file)
var fileReader = new FileReader();
fileReader.onload = function()var fileData = fileReader.result;
fileReader.readAsText(file);
fileEntry.file(read);
directoryEntry.getFile(
"testFile",
create: false,
readFile
);
requestFileSystem(Window.PERSISTENT, grantedQuota, getFile);
var desiredQuota = 1024 * 1024 * 1024;
var quotaManagementObj = navigator.webkitPersistentStorage;
quotaManagementObj.requestQuota(desiredQuota, onQuotaRequestSuccess);
Just what you asked for right? Maybe, maybe not. The latter two of the APIs:
- Are currently only implemented in Chromium-based browsers (Chrome & Opera)
- Have been taken off the W3C standards track, and as of now are proprietary APIs
- May be removed from the implementing browsers in the future
- Constrict the creation of files to a sandbox (a location outside of which the files can produce no effect) on disk
Additionally, the FileSystem spec defines no guidelines on how directory structures are to appear on disk. In Chromium-based browsers for example, the sandbox has a virtual file system (a directory structure which does not necessarily exist on disk in the same form that it does when accessed from within the browser), within which the directories and files created with the APIs are placed.
So though you may be able to write files to a system with the APIs, locating the files without the APIs (well, without the FileSystem API) could be a non-trivial affair.
If you can deal with these issues/limitations, these APIs are pretty much the only native way to do what you've asked.
If you're open to non-native solutions, Silverlight also allows for file i/o from a tab/window contest through IsolatedStorage. However, managed code is required to utilize this facility; a solution which requires writing such code is beyond the scope of this question.
Of course, a solution which makes use of complementary managed code, leaving one with only Javascript to write, is well within the scope of this question ;) :
//Write file to first of either FileSystem or IsolatedStorage
bakedGoods.set(
data: [key: "testFile", value: "Hello world!", dataFormat: "text/plain"],
storageTypes: ["fileSystem", "silverlight"],
options: fileSystem:storageType: Window.PERSISTENT,
complete: function(byStorageTypeStoredItemRangeDataObj, byStorageTypeErrorObj)
);
* BakedGoods is a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities. It is maintained by this guy right here : ) .
edited Jul 7 '16 at 0:27
answered Jul 7 '16 at 0:21
KevinKevin
1,5672432
1,5672432
add a comment |
add a comment |
In the context of browser, Javascript can READ user-specified file. See Eric Bidelman's blog for detail about reading file using File API.
However, it is not possible for browser-based Javascript to WRITE the file system of local computer without disabling some security settings because it is regarded as a security threat for any website to change your local file system arbitrarily.
Saying that, there are some ways to work around it depending what you are trying to do:
If it is your own site, you can embed a Java Applet in the web page. However, the visitor has to install Java on local machine and will be alerted about the security risk. The visitor has to allow the applet to be loaded. An Java Applet is like an executable software that has complete access to the local computer.
Chrome supports a file system which is a sandboxed portion of the local file system. See this page for details. This provides possibly for you to temporarily save things locally. However, this is not supported by other browsers.
If you are not limited to browser, Node.js has a complete file system interface. See here for its file system documentation. Note that Node.js can run not only on servers, but also any client computer including windows. The javascript test runner Karma is based on Node.js. If you just like to program in javascript on the local computer, this is an option.
add a comment |
In the context of browser, Javascript can READ user-specified file. See Eric Bidelman's blog for detail about reading file using File API.
However, it is not possible for browser-based Javascript to WRITE the file system of local computer without disabling some security settings because it is regarded as a security threat for any website to change your local file system arbitrarily.
Saying that, there are some ways to work around it depending what you are trying to do:
If it is your own site, you can embed a Java Applet in the web page. However, the visitor has to install Java on local machine and will be alerted about the security risk. The visitor has to allow the applet to be loaded. An Java Applet is like an executable software that has complete access to the local computer.
Chrome supports a file system which is a sandboxed portion of the local file system. See this page for details. This provides possibly for you to temporarily save things locally. However, this is not supported by other browsers.
If you are not limited to browser, Node.js has a complete file system interface. See here for its file system documentation. Note that Node.js can run not only on servers, but also any client computer including windows. The javascript test runner Karma is based on Node.js. If you just like to program in javascript on the local computer, this is an option.
add a comment |
In the context of browser, Javascript can READ user-specified file. See Eric Bidelman's blog for detail about reading file using File API.
However, it is not possible for browser-based Javascript to WRITE the file system of local computer without disabling some security settings because it is regarded as a security threat for any website to change your local file system arbitrarily.
Saying that, there are some ways to work around it depending what you are trying to do:
If it is your own site, you can embed a Java Applet in the web page. However, the visitor has to install Java on local machine and will be alerted about the security risk. The visitor has to allow the applet to be loaded. An Java Applet is like an executable software that has complete access to the local computer.
Chrome supports a file system which is a sandboxed portion of the local file system. See this page for details. This provides possibly for you to temporarily save things locally. However, this is not supported by other browsers.
If you are not limited to browser, Node.js has a complete file system interface. See here for its file system documentation. Note that Node.js can run not only on servers, but also any client computer including windows. The javascript test runner Karma is based on Node.js. If you just like to program in javascript on the local computer, this is an option.
In the context of browser, Javascript can READ user-specified file. See Eric Bidelman's blog for detail about reading file using File API.
However, it is not possible for browser-based Javascript to WRITE the file system of local computer without disabling some security settings because it is regarded as a security threat for any website to change your local file system arbitrarily.
Saying that, there are some ways to work around it depending what you are trying to do:
If it is your own site, you can embed a Java Applet in the web page. However, the visitor has to install Java on local machine and will be alerted about the security risk. The visitor has to allow the applet to be loaded. An Java Applet is like an executable software that has complete access to the local computer.
Chrome supports a file system which is a sandboxed portion of the local file system. See this page for details. This provides possibly for you to temporarily save things locally. However, this is not supported by other browsers.
If you are not limited to browser, Node.js has a complete file system interface. See here for its file system documentation. Note that Node.js can run not only on servers, but also any client computer including windows. The javascript test runner Karma is based on Node.js. If you just like to program in javascript on the local computer, this is an option.
edited Jan 4 '16 at 9:51
answered May 12 '15 at 15:20
gm2008gm2008
2,94612935
2,94612935
add a comment |
add a comment |
You'll have to turn to Flash, Java or Silverlight. In the case of Silverlight, you'll be looking at Isolated Storage. That will get you write to files in your own playground on the users disk. It won't let you write outside of your playground though.
add a comment |
You'll have to turn to Flash, Java or Silverlight. In the case of Silverlight, you'll be looking at Isolated Storage. That will get you write to files in your own playground on the users disk. It won't let you write outside of your playground though.
add a comment |
You'll have to turn to Flash, Java or Silverlight. In the case of Silverlight, you'll be looking at Isolated Storage. That will get you write to files in your own playground on the users disk. It won't let you write outside of your playground though.
You'll have to turn to Flash, Java or Silverlight. In the case of Silverlight, you'll be looking at Isolated Storage. That will get you write to files in your own playground on the users disk. It won't let you write outside of your playground though.
answered Feb 25 '09 at 17:17
Cory R. KingCory R. King
2,06812121
2,06812121
add a comment |
add a comment |
To create file try
function makefile()
var fso;
var thefile;
fso = new ActiveXObject("Scripting.FileSystemObject");
thefile=fso.CreateTextFile("C:\tmp\MyFile.txt",true);
thefile.close()
Create your directory in the C drive because windows has security against writing from web
e.g create folder named "tmp" in C drive.
2
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
add a comment |
To create file try
function makefile()
var fso;
var thefile;
fso = new ActiveXObject("Scripting.FileSystemObject");
thefile=fso.CreateTextFile("C:\tmp\MyFile.txt",true);
thefile.close()
Create your directory in the C drive because windows has security against writing from web
e.g create folder named "tmp" in C drive.
2
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
add a comment |
To create file try
function makefile()
var fso;
var thefile;
fso = new ActiveXObject("Scripting.FileSystemObject");
thefile=fso.CreateTextFile("C:\tmp\MyFile.txt",true);
thefile.close()
Create your directory in the C drive because windows has security against writing from web
e.g create folder named "tmp" in C drive.
To create file try
function makefile()
var fso;
var thefile;
fso = new ActiveXObject("Scripting.FileSystemObject");
thefile=fso.CreateTextFile("C:\tmp\MyFile.txt",true);
thefile.close()
Create your directory in the C drive because windows has security against writing from web
e.g create folder named "tmp" in C drive.
edited Dec 20 '11 at 20:17
BurninatorDor
52051235
52051235
answered Mar 31 '11 at 15:40
Ifiok IdiangIfiok Idiang
287135
287135
2
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
add a comment |
2
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
2
2
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
Will this work in Internet Explorer only?
– Anderson Green
Aug 3 '12 at 17:52
add a comment |
You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write files, but that is it unfortunately.
If you are looking to save user information, you will most likely need to use cookies.
4
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
add a comment |
You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write files, but that is it unfortunately.
If you are looking to save user information, you will most likely need to use cookies.
4
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
add a comment |
You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write files, but that is it unfortunately.
If you are looking to save user information, you will most likely need to use cookies.
You can't do this in any cross-browser way. IE does have methods to enable "trusted" applications to use ActiveX objects to read/write files, but that is it unfortunately.
If you are looking to save user information, you will most likely need to use cookies.
answered Feb 25 '09 at 9:08
Philip ReynoldsPhilip Reynolds
8,33332435
8,33332435
4
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
add a comment |
4
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
4
4
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
And the barrier to becoming a "trusted" application is what precisely? A confirmation dialogue?
– Breton
Feb 25 '09 at 10:03
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
@Philip, No one said it needs to be cross browser. A different solution for each browser is fine.
– Pacerier
Jun 26 '15 at 23:39
add a comment |
From a ReactJS test, the following code successfully writes a file:
import writeJsonFile from 'write-json-file';
const ans = 42;
writeJsonFile('answer.txt', ans);
const json = "answer": ans;
writeJsonFile('answer_json.txt', json);
The file is written to the directory containing the tests, so writing to an actual JSON file '*.json' creates a loop!
add a comment |
From a ReactJS test, the following code successfully writes a file:
import writeJsonFile from 'write-json-file';
const ans = 42;
writeJsonFile('answer.txt', ans);
const json = "answer": ans;
writeJsonFile('answer_json.txt', json);
The file is written to the directory containing the tests, so writing to an actual JSON file '*.json' creates a loop!
add a comment |
From a ReactJS test, the following code successfully writes a file:
import writeJsonFile from 'write-json-file';
const ans = 42;
writeJsonFile('answer.txt', ans);
const json = "answer": ans;
writeJsonFile('answer_json.txt', json);
The file is written to the directory containing the tests, so writing to an actual JSON file '*.json' creates a loop!
From a ReactJS test, the following code successfully writes a file:
import writeJsonFile from 'write-json-file';
const ans = 42;
writeJsonFile('answer.txt', ans);
const json = "answer": ans;
writeJsonFile('answer_json.txt', json);
The file is written to the directory containing the tests, so writing to an actual JSON file '*.json' creates a loop!
answered Nov 14 '18 at 15:55
Steve PitchersSteve Pitchers
5,08943136
5,08943136
add a comment |
add a comment |
You cannot do file i/o on the client side using javascript as that would be a security risk. You'd either have to get them to download and run an exe, or if the file is on your server, use AJAX and a server-side language such as PHP to do the i/o on serverside
1
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
add a comment |
You cannot do file i/o on the client side using javascript as that would be a security risk. You'd either have to get them to download and run an exe, or if the file is on your server, use AJAX and a server-side language such as PHP to do the i/o on serverside
1
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
add a comment |
You cannot do file i/o on the client side using javascript as that would be a security risk. You'd either have to get them to download and run an exe, or if the file is on your server, use AJAX and a server-side language such as PHP to do the i/o on serverside
You cannot do file i/o on the client side using javascript as that would be a security risk. You'd either have to get them to download and run an exe, or if the file is on your server, use AJAX and a server-side language such as PHP to do the i/o on serverside
answered Feb 25 '09 at 9:09
Click UpvoteClick Upvote
99.6k231514695
99.6k231514695
1
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
add a comment |
1
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
1
1
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– harpun
Nov 12 '13 at 20:32
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
@harpun, Exactly. Please delete this answer and convert it into a comment.
– Pacerier
Jun 26 '15 at 23:43
add a comment |
There are two ways to read and write a file using JavaScript
Using JavaScript extensions
Using a web page and Active X objects
add a comment |
There are two ways to read and write a file using JavaScript
Using JavaScript extensions
Using a web page and Active X objects
add a comment |
There are two ways to read and write a file using JavaScript
Using JavaScript extensions
Using a web page and Active X objects
There are two ways to read and write a file using JavaScript
Using JavaScript extensions
Using a web page and Active X objects
answered Nov 14 '18 at 21:40
Grigor IWTGrigor IWT
12713
12713
add a comment |
add a comment |
Here is write solution for chrome v52+ (user still need to select a destination doe...)
source: StreamSaver.js
<!-- load StreamSaver.js before streams polyfill to detect support -->
<script src="StreamSaver.js"></script>
<script src="https://wzrd.in/standalone/web-streams-polyfill@latest"></script>
const writeStream = streamSaver.createWriteStream('filename.txt')
const encoder = new TextEncoder
let data = 'a'.repeat(1024)
let uint8array = encoder.encode(data + "nn")
writeStream.write(uint8array) // must be uInt8array
writeStream.close()
Best suited for writing large data generated on client side.
Otherwise I suggest using FileSaver.js to save Blob/Files
add a comment |
Here is write solution for chrome v52+ (user still need to select a destination doe...)
source: StreamSaver.js
<!-- load StreamSaver.js before streams polyfill to detect support -->
<script src="StreamSaver.js"></script>
<script src="https://wzrd.in/standalone/web-streams-polyfill@latest"></script>
const writeStream = streamSaver.createWriteStream('filename.txt')
const encoder = new TextEncoder
let data = 'a'.repeat(1024)
let uint8array = encoder.encode(data + "nn")
writeStream.write(uint8array) // must be uInt8array
writeStream.close()
Best suited for writing large data generated on client side.
Otherwise I suggest using FileSaver.js to save Blob/Files
add a comment |
Here is write solution for chrome v52+ (user still need to select a destination doe...)
source: StreamSaver.js
<!-- load StreamSaver.js before streams polyfill to detect support -->
<script src="StreamSaver.js"></script>
<script src="https://wzrd.in/standalone/web-streams-polyfill@latest"></script>
const writeStream = streamSaver.createWriteStream('filename.txt')
const encoder = new TextEncoder
let data = 'a'.repeat(1024)
let uint8array = encoder.encode(data + "nn")
writeStream.write(uint8array) // must be uInt8array
writeStream.close()
Best suited for writing large data generated on client side.
Otherwise I suggest using FileSaver.js to save Blob/Files
Here is write solution for chrome v52+ (user still need to select a destination doe...)
source: StreamSaver.js
<!-- load StreamSaver.js before streams polyfill to detect support -->
<script src="StreamSaver.js"></script>
<script src="https://wzrd.in/standalone/web-streams-polyfill@latest"></script>
const writeStream = streamSaver.createWriteStream('filename.txt')
const encoder = new TextEncoder
let data = 'a'.repeat(1024)
let uint8array = encoder.encode(data + "nn")
writeStream.write(uint8array) // must be uInt8array
writeStream.close()
Best suited for writing large data generated on client side.
Otherwise I suggest using FileSaver.js to save Blob/Files
answered Jun 11 '16 at 22:42
EndlessEndless
12.8k65471
12.8k65471
add a comment |
add a comment |
protected by Community♦ Nov 13 '14 at 22:08
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
2
Why do you need it? Maybe there are workarounds.
– Ionuț G. Stan
Feb 25 '09 at 17:22
6
dupe: stackoverflow.com/questions/582268/jquery-read-write-to-file/…
– Paolo Bergantino
Feb 25 '09 at 17:24
1
has been asked many times before in fact
– annakata
Feb 25 '09 at 17:27
1
I found this resource regarding client-side file storage. html5rocks.com/en/tutorials/offline/storage From what I've gathered, HTML5 actually allows Websights to store information on the user's local hard drive, but in a more database-like manor. The browser manages the file storage and imposes certain limits to prevent the World Wide Web from loading peoples hard drives down to the brim. They're not completely fool proof yet, but they're being tweaked, at least according to this article. Have a read for details.
– Garrett
Dec 28 '16 at 3:02
1
Use Ajax and with PHP handle reading and writing files. If you want to handle writing to files client side, you should forget it. It would require many security options to be disabled on the server and you would be left with an extremely insecure site. If you don't want to use PHP, maybe what you want to achieve can be done by using JavaScript Cookies to store data on the clients computer.
– Dan Bray
Jan 14 '17 at 20:24