简体   繁体   中英

How do I detect the temporary Internet Files location of Internet Explorer through Javascript?

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?

fso.GetSpecialFolder(2)

Found here: FileSystemObject.GetSpecialFolder()

FileSystemObject.GetSpecialFolder(2) will give you temp folder path of OS. It wont give you Temporary internet files' location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM