替换ActiveXobject('scipping.filesystemobject");
重构旧的JavaScript代码,以下ActiveX代码的有效替换是什么?只是有能力编写本地文件。
function WriteToFile(bufObj, fileName) {
var fileObj;
fileObj = new ActiveXObject("Scripting.FileSystemObject");
fileObj = fileObj.OpenTextFile(fileName, ForWriting, true, TristateMixed);
fileObj.Write(bufObj);
fileObj.Close();
}
Refactoring old javascript code, what is an effective replacement for the below ActiveX code? Just having the ability to write a local file.
function WriteToFile(bufObj, fileName) {
var fileObj;
fileObj = new ActiveXObject("Scripting.FileSystemObject");
fileObj = fileObj.OpenTextFile(fileName, ForWriting, true, TristateMixed);
fileObj.Write(bufObj);
fileObj.Close();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在现代浏览器中没有能力。 (除非有人疯狂以至于仍然允许ActiveX控件 - 没有人会再做)。
本地文件系统是100%移交!!!
如果允许这个?
然后,当您来到我的网站看可爱的猫图片时?
然后,我要四处逛逛 - 上传说一个称为“我的密码”的文本文件。还是我四处逛逛,寻找一个名为我的银行业务的文件?
还是抓住所有电子邮件?
实际上,您的JavaScript在使用文件上加载时甚至无法选择或设置文件。因此,不允许任何类型的本地文件访问,并且不可能解决问题。
如果允许这样做,那么没有人会再使用或再次信任互联网!
这是一个远大的安全孔。现在,也许这可能是一些内部的“仅”网站,并且可以允许某种本地文件权利和访问权限?那是这样吗?您必须继续允许和设置浏览器以允许该内部站点的ActiveX-但这是一次高风险冒险。
因此,您没有替代品,因为浏览器甚至从触摸,知道或了解客户端文件夹中都锁定了代码。除此之外,用户可能在其Android手机或iPad上 - 无论如何他们都有相当不同的文件系统(而且他们也不支持ActiveX)。
因此,现代浏览器的能力为零,我重复零能力看到,触摸,了解任何本地文件的存在 - 简单不允许。关于这个问题的唯一方法是找到仍然支持并允许ActiveX的浏览器 - 在这几天之间,它们却很少。
You don't have that ability in a modern browser. (unless someone is crazy enough to still allow ActiveX controls - which no one does anymore).
the local file system is 100% HANDS off!!!
If you allow this?
Then when you come to my site to look at a cute cat picture?
Then I am going to rummage around - and up-load say a text file called "my passwords". Or how about I go rummage around and look for a file called my banking?
or grab all your emails?
In fact, your JavaScript cannot even SELECT or set a file when using the file-up-load. So, any kind of local file access is not allowed, and is out of the question.
If this was to be allowed, then no one would ever use nor trust the internet again!
It is a security hole far to large. Now perhaps this might be some internal "only" web site, and some kind of local file rights and access is to be allowed? That being the case? You have to continue to allow and setup the browser to allow ActiveX for that internal site - but this is a high risk adventure.
So, you don't have a replacement, since browsers are locked down from code even touching, knowing or having ANY knowledge of the client side folders. Beside, the user might be on their Android phone, or a iPad - and they have rather different file systems anyway (and they don't have support for ActiveX either).
So, modern browsers have ZERO ability, I repeat ZERO ability to see, touch, know about the existence of ANY local file - it simple not allowed. About the only way around this issue would be to find a browser that still supports and allows ActiveX - and they are far and few between these days.