0

I want to modify a .txt (overwrite completely) using javascript/jquery. I am currently using the code written below and it is working fine in IE.

    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.OpenTextFile(dir + "modules.txt", 2, true, -2);
    s.WriteLine(tobewritten);
    s.Close();
    fso = s = null;

How can the same be done in Mozilla firefox.

Please note that I am running my application locally and not hosted on a webserver.

Ashish
  • 63
  • 1
  • 4

2 Answers2

4

It can't. All in-browser JavaScript is sandboxed, so it will never actually allow you to access any local directory.

You can only get around this 'limitation' (I put that in quotes because it's very much purposeful) is to use a browser plugin, like running in-browser Java code or similar, and then use that to access local files.

Fenixp
  • 645
  • 5
  • 22
0

It is possible using HTML5 FileSystem API.

You should be able to achieve following:

  1. Reading and manipulating files: File/Blob, FileList, FileReader
  2. Creating and writing: Blob(), FileWriter
  3. Directories and file system access: DirectoryReader, FileEntry/DirectoryEntry, LocalFileSystem

More information available here. & here.

Note: This is only supported by modern browsers yet. In fact most of the features are supported in chrome only. Unfortunately firefox doesn't support writing files using FileAPI but they are likely to implement this in future according to this.

Check browser support.

Gurpreet Singh
  • 20,907
  • 5
  • 44
  • 60
  • That ["check browser support"](http://caniuse.com/#feat=filesystem) link explicitly says that Firefox doesn't support this technique, which is the only thing the OP asked for. – Blazemonger Oct 04 '13 at 12:46
  • Why is your updated link more correct than the original one? Looks to me like the FileWriter API is what the OP needs. – Blazemonger Oct 04 '13 at 12:59
  • These links are bit confusion actually. After doing some googling I found out writing is still not supported by firefox. I'll Update. – Gurpreet Singh Oct 04 '13 at 13:14