admin管理员组文章数量:1024904
I am dynamically generating an HTML file for the print option.
After the print window has been opened and the file printed, I want to remove the HTML file from the folder.
I need to do this with JavaScript. For this I am using the following code:
var myObject = new ActiveXObject("Scripting.FileSystemObject");
var myFolder = myObject.GetFile(strReportFilePath);
myFolder.Delete();`
But this only works in IE but not in Firefox, so how do I delete the file with a JavaScript function?
I am dynamically generating an HTML file for the print option.
After the print window has been opened and the file printed, I want to remove the HTML file from the folder.
I need to do this with JavaScript. For this I am using the following code:
var myObject = new ActiveXObject("Scripting.FileSystemObject");
var myFolder = myObject.GetFile(strReportFilePath);
myFolder.Delete();`
But this only works in IE but not in Firefox, so how do I delete the file with a JavaScript function?
Share Improve this question edited Mar 21, 2013 at 19:19 Alex Nolasco 19.5k9 gold badges90 silver badges83 bronze badges asked Aug 18, 2011 at 12:53 MNRMNR 1,0737 gold badges23 silver badges38 bronze badges 8- On the client or on the server? What browsers do you need to support? How are you generating the HTML file? – Pekka Commented Aug 18, 2011 at 12:54
- I didn't know you can actually do it in IE, I thought it was impossible. I think it is impossible in Firefox, though. – Igor Zinov'yev Commented Aug 18, 2011 at 12:55
- 2 The simple answer is "you cannot". Security model does not allow javascript to interact with the client file system. If it were possible, then, theoretically, any page from any website could delete any file from your machine. – Aleks G Commented Aug 18, 2011 at 12:56
- 1 You used Jscript, not Javascript. JScript is a "Javascriptextension" as the a part of Windows Scripting Host (short WSH). Becaused it uses the DCOM, you can only execute it with browsers whose can deal with ActiveX ponents. The most famous representative of those is the Internet Explorer. – Reporter Commented Aug 18, 2011 at 13:02
- 1 I repeat. Where is the HTML file located, on the client or on the server? That is the main question here. – Pekka Commented Aug 18, 2011 at 13:02
2 Answers
Reset to default 5You can't. JavaScript is sandboxed. With IE, you are using ActiveX to do the dirty work.
I'm on the look out for just accessing files on the local files and failed to find a way that works cross-browser easily yet. However you might want to try signed Java applets which seemed to be a (though not so smooth) solution.
You also might want to keep track of this
I am dynamically generating an HTML file for the print option.
After the print window has been opened and the file printed, I want to remove the HTML file from the folder.
I need to do this with JavaScript. For this I am using the following code:
var myObject = new ActiveXObject("Scripting.FileSystemObject");
var myFolder = myObject.GetFile(strReportFilePath);
myFolder.Delete();`
But this only works in IE but not in Firefox, so how do I delete the file with a JavaScript function?
I am dynamically generating an HTML file for the print option.
After the print window has been opened and the file printed, I want to remove the HTML file from the folder.
I need to do this with JavaScript. For this I am using the following code:
var myObject = new ActiveXObject("Scripting.FileSystemObject");
var myFolder = myObject.GetFile(strReportFilePath);
myFolder.Delete();`
But this only works in IE but not in Firefox, so how do I delete the file with a JavaScript function?
Share Improve this question edited Mar 21, 2013 at 19:19 Alex Nolasco 19.5k9 gold badges90 silver badges83 bronze badges asked Aug 18, 2011 at 12:53 MNRMNR 1,0737 gold badges23 silver badges38 bronze badges 8- On the client or on the server? What browsers do you need to support? How are you generating the HTML file? – Pekka Commented Aug 18, 2011 at 12:54
- I didn't know you can actually do it in IE, I thought it was impossible. I think it is impossible in Firefox, though. – Igor Zinov'yev Commented Aug 18, 2011 at 12:55
- 2 The simple answer is "you cannot". Security model does not allow javascript to interact with the client file system. If it were possible, then, theoretically, any page from any website could delete any file from your machine. – Aleks G Commented Aug 18, 2011 at 12:56
- 1 You used Jscript, not Javascript. JScript is a "Javascriptextension" as the a part of Windows Scripting Host (short WSH). Becaused it uses the DCOM, you can only execute it with browsers whose can deal with ActiveX ponents. The most famous representative of those is the Internet Explorer. – Reporter Commented Aug 18, 2011 at 13:02
- 1 I repeat. Where is the HTML file located, on the client or on the server? That is the main question here. – Pekka Commented Aug 18, 2011 at 13:02
2 Answers
Reset to default 5You can't. JavaScript is sandboxed. With IE, you are using ActiveX to do the dirty work.
I'm on the look out for just accessing files on the local files and failed to find a way that works cross-browser easily yet. However you might want to try signed Java applets which seemed to be a (though not so smooth) solution.
You also might want to keep track of this
本文标签: How to delete a file from physical directory with JavaScript (WindowsIE Only)Stack Overflow
版权声明:本文标题:How to delete a file from physical directory with JavaScript (WindowsIE Only)? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745497396a2153229.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论