ActiveXObject FileSystemObject not releasing in Javascript

心不动则不痛 提交于 2019-12-13 08:14:46

问题


I have a Javascript function that saves JSON data locally, using an ActiveXObject in IE9. It links into FileSystemObject or FSO scripting for file access.

If this Javascript function is run more than once, I get an error in IE debugger: "SCRIPT70: Permission denied" pointing to ts = savefile.OpenAsTextStream(2);

Why will it run just fine the first time, but not after that? My best guess is that something's not being released properly, although I can find no information on MSDN (or here).

Here's the code:

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;
}

回答1:


The Close method needs empty parenthesis after it, like so:

ts.Close();

Ref here for more info.



来源:https://stackoverflow.com/questions/25191200/activexobject-filesystemobject-not-releasing-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!