使用javascript/jquery编辑txt文件 [英] Edit a txt file using javascript/jquery

查看:123
本文介绍了使用javascript/jquery编辑txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用javascript/jquery修改.txt(完全覆盖).我目前正在使用下面编写的代码,并且在IE中工作正常.

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;

如何在Mozilla firefox中完成同样的操作.

How can the same be done in Mozilla firefox.

请注意,我在本地运行我的应用程序,而不是在网络服务器上托管.

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

推荐答案

不能.所有浏览器内的JavaScript都经过沙箱处理,因此实际上它永远不会允许您访问任何本地目录.

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

您只能绕开这个限制"(我把它加引号是因为它很有用)是使用浏览器插件,例如运行浏览器内的Java代码或类似代码,然后使用它来访问本地文件.

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.

这篇关于使用javascript/jquery编辑txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆