如何通过 Javascript 检测 Internet Explorer 的临时 Internet 文件位置?
我正在尝试将 Firefox 扩展移植到 IE。我需要的功能之一是能够写入浏览器的临时文件。在 Firefox 中,这可以通过以下代码轻松完成:
//Create file to store data transferred to desktop app
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("TmpD", Components.interfaces.nsIFile);
file.append("MyExtTempFile.txt");
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
// do whatever you need to the created file
这种方法比硬编码路径更可取,因为它可能会在不同版本的 Windows/IE 上发生变化。
我想出了如何在 IE 中创建和写入文件:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("C:\\Users\\Administrator\\Desktop\\MyExtTempFile.txt", true);
fh.WriteLine("Some text goes here...");
fh.Close();
现在我只是想知道如何自动检测 IE 的临时文件位置?
I am attempting to port an Firefox extension to IE. One of the features I need to have is the ability to write to the Temp Files of the browser. In Firefox this was easily done by the following code:
//Create file to store data transferred to desktop app
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("TmpD", Components.interfaces.nsIFile);
file.append("MyExtTempFile.txt");
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
// do whatever you need to the created file
This method was preferable rather than hard coding a path in because it could change on different versions of Windows / IE.
I figured out how to create and write to a file in IE by:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("C:\\Users\\Administrator\\Desktop\\MyExtTempFile.txt", true);
fh.WriteLine("Some text goes here...");
fh.Close();
Now I am just wondering how to automatically detect the temp file location for IE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这里找到:FileSystemObject.GetSpecialFolder()
Found here: FileSystemObject.GetSpecialFolder()
FileSystemObject.GetSpecialFolder(2)
将为您提供操作系统的临时文件夹路径。它不会为您提供临时互联网文件的位置。FileSystemObject.GetSpecialFolder(2)
will give you temp folder path of OS. It wont give you Temporary internet files' location.