【问题标题】:ActiveXObject FileSystemObject not releasing in JavascriptActiveXObject FileSystemObject 未在 Javascript 中发布
【发布时间】:2014-08-07 20:00:44
【问题描述】:

我有一个 Javascript 函数,它使用 IE9 中的 ActiveXObject 在本地保存 JSON 数据。它链接到 FileSystemObject 或 FSO 脚本以进行文件访问。

如果此 Javascript 函数多次运行,我会在 IE 调试器中收到错误:“SCRIPT70: Permission denied”指向ts = savefile.OpenAsTextStream(2);

为什么它第一次运行得很好,但之后就不行了?我最好的猜测是某些内容没有正确发布,尽管我找不到关于MSDN(或here)的信息。

代码如下:

function SaveMyJSON() {
    var ts; 
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var savefilepath = "C:\\MyFolder\\saveFile.json"
    var savefile = fso.GetFile(savefilepath);

    // open for writing only, value 2, overwriting the previous
    // contents of the file
    ts = savefile.OpenAsTextStream(2);

    var myTestJson = {"id1" : "one", "id2" : "two"};

    // copy to json
    ts.WriteLine(myTestJson);

    ts.Close;
}

【问题讨论】:

  • 为什么投反对票?这符合 SO 的标准。也许您无法帮助它,因为这是一个 ActiveX 问题...

标签: javascript scripting activexobject fso


【解决方案1】:

Close 方法后面需要空括号,如下所示:

ts.Close();

请参考here 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多