[英]How do I detect the temporary Internet Files location of Internet Explorer through Javascript?
I am attempting to port an Firefox extension to IE.我正在尝试将 Firefox 扩展移植到 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:
在 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
This method was preferable rather than hard coding a path in because it could change on different versions of Windows / IE.这种方法比硬编码路径更可取,因为它可能会在 Windows / IE 的不同版本上发生变化。
I figured out how to create and write to a file in IE by:我想出了如何通过以下方式在 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();
Now I am just wondering how to automatically detect the temp file location for IE?现在我只是想知道如何自动检测 IE 的临时文件位置?
fso.GetSpecialFolder(2)
Found here: FileSystemObject.GetSpecialFolder()在这里找到: FileSystemObject.GetSpecialFolder()
FileSystemObject.GetSpecialFolder(2)
will give you temp folder path of OS. FileSystemObject.GetSpecialFolder(2)
将为您提供操作系统的临时文件夹路径。 It wont give you Temporary internet files' location.它不会为您提供临时 Internet 文件的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.