写在JavaScript到文件。不工作 [英] Writing to file in javascript. not working

查看:115
本文介绍了写在JavaScript到文件。不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我曾与我的HTML / JavaScript的code问题:
    
    

Hello i have had problems with my html/javascript code:

function rf()
{

    var fs,file;

    fs = new ActiveXObject('Scripting.FileSystemObject');

    file = fs.OpenTextFile('/test123.txt',2);

    file.Write('The text to write to file');

    file.Close();

}

</script>
<button onclick="rf()">Try it</button>
</html>

我去的页面上,按一下按钮,没有成功。有人可以给我纠正呢?

i go on the page, click the button, no success. can someone correct this for me?

推荐答案

即使Internet Explorer不会允许这种构造在默认情况下,在任何版本 - 你需要手动切换一些非常危险的设置,允许这一点。的Javascript在浏览器中的全部目的是,它是<青霉>沙盒的浏览器进程内,并且在所有访问,甚至更糟写入,周围计算机及其文件系统的任何手段。如果这个code会的工作,你会停止做同样的你的 System32下文件夹内的文件的人?或的hiberfil.sys ?或 autoexec.bat文件?不用说,你要实现的目标不能也不应该永远工作,在任何计算机上,在任何浏览器。

Even Internet Explorer does not allow this construct by default, in any version - you'll need to manually switch some very dangerous settings to allow this. The whole purpose of Javascript in a browser is that it is sandboxed inside the browser process, and has no means at all of accessing, or even worse writing to, the surrounding computer and its filesystems. If this code would work, what would stop someone from doing the same with files inside your System32 folder? Or hiberfil.sys? Or autoexec.bat? Needless to say, what you are trying to achieve cannot and should not ever work, on any computer, in any browser.

关于这个问题

由于使用FSO在客户端可能潜在地提供
  不受欢迎的访问客户端的本地文件系统,你应该使用它
  仅在服务器端执行的脚本。 IE的默认
  安全设置不允许客户端使用FileSystemObject的
  目的。覆盖这些默认值可能受到本地计算机
  不受欢迎访问文件系统,这可能导致在总
  破坏文件系统的完整性,数据的造成损失,或
  更糟糕。

Because using the FSO on the client side may provide potentially unwelcome access to a client's local file system, you should use it only in scripts executed on the server side. Internet Explorer default security settings do not allow client-side use of the FileSystemObject object. Overriding those defaults could subject a local computer to unwelcome access to the file system, which could result in total destruction of the file system's integrity, causing loss of data, or worse.

这篇关于写在JavaScript到文件。不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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