firefox - How to enable local javascript to readwrite files on my PC? - Stack Overflow

Since Greasemonkey can't readwrite files from a local hard disk, I've heard people suggestin

Since Greasemonkey can't read/write files from a local hard disk, I've heard people suggesting Google gears but I've no idea about gears.

So, I've decided to add a

<script type="text/javascript" src="file:///c:/test.js">/script>

Now, this test will use FileSystemObject to read/write file. Since, the file:///c:/test.js is a javascript file from local hard disk, it should probably be able to read/write file on my local hard disk.

I tried it but Firefox prevented the file:///c:/test.js script to read/write files from the local disk. :(

Is there any setting in Firefox's about:config where we can specify to let a particular script, say from localfile or xyz, to have read/write permission on my local disk files?

Since Greasemonkey can't read/write files from a local hard disk, I've heard people suggesting Google gears but I've no idea about gears.

So, I've decided to add a

<script type="text/javascript" src="file:///c:/test.js">/script>

Now, this test will use FileSystemObject to read/write file. Since, the file:///c:/test.js is a javascript file from local hard disk, it should probably be able to read/write file on my local hard disk.

I tried it but Firefox prevented the file:///c:/test.js script to read/write files from the local disk. :(

Is there any setting in Firefox's about:config where we can specify to let a particular script, say from localfile or xyz., to have read/write permission on my local disk files?

Share Improve this question edited Oct 10, 2013 at 6:56 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked May 17, 2010 at 0:14 Nok ImchenNok Imchen 2,8427 gold badges36 silver badges59 bronze badges 1
  • 1 It's not the location of the script that determines the Origin it operates in under the Same Origin Policy, but the location of the page including the script. In any case, ‘FileSystemObject’ is an ActiveX control so no such thing exists in Firefox. – bobince Commented May 17, 2010 at 1:19
Add a ment  | 

1 Answer 1

Reset to default 4

You can use these within chrome scope.

var FileManager =
{
Write:
    function (File, Text)
    {
        if (!File) return;
        const unicodeConverter = Components.classes["@mozilla/intl/scriptableunicodeconverter"]
            .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);

        unicodeConverter.charset = "UTF-8";

        Text = unicodeConverter.ConvertFromUnicode(Text);
        const os = Components.classes["@mozilla/network/file-output-stream;1"]
          .createInstance(Components.interfaces.nsIFileOutputStream);
        os.init(File, 0x02 | 0x08 | 0x20, 0700, 0);
        os.write(Text, Text.length);
        os.close();
    },

Read:
    function (File)
    {
        if (!File) return;
        var res;

        const is = Components.classes["@mozilla/network/file-input-stream;1"]
            .createInstance(Components.interfaces.nsIFileInputStream);
        const sis = Components.classes["@mozilla/scriptableinputstream;1"]
            .createInstance(Components.interfaces.nsIScriptableInputStream);
        is.init(File, 0x01, 0400, null);
        sis.init(is);

        res = sis.read(sis.available());

        is.close();

        return res;
    },
}

Example:

var x = FileManager.Read("C:\\test.js");

See Also

  • Full File class from OneManga Manager addon
  • Reading a file inside the addon using OMM File class

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744369747a4570887.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信