DownloadLastDir.jsm 编辑
The DownloadLastDir.jsm
JavaScript code module lets you retrieve the path of the last directory into which a download occurred.
To use this, you first need to import the code module into your JavaScript scope:
Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
If you are using Addon SDK, you can import the code module as:
let { Cu } = require("chrome"); let DownloadLastDir = Cu.import("resource://gre/modules/DownloadLastDir.jsm").DownloadLastDir;
Once you've imported the module, you can then use the DownloadLastDir
object it exports.
Using the DownloadLastDir object
To determine or set the path into which the last download occurred:
// file is an nsIFile var file = DownloadLastDir.file; DownloadLastDir.file = file;
You can also set and retrieve this information on a site-by-site basis.
To set the path, use setFile
:
// file is an nsIFile DownloadLastDir.setFile(uri, file);
To retrieve the path in Firefox 26 or later, use getFileAsync
:
DownloadLastDir.getFileAsync(uri, function (file) { // file is an nsIFile console.log(file); });
Deprecated since Gecko 26.0 To retrieve the path in Firefox 25 or earlier, use getFile
:
// file is an nsIFile var file = gDownloadLastDir.getFile(uri); console.log(file);
Private browsing mode
When browsing normally, the browser uses the browser.download.lastDir
preference to store the last download directory path. However, when private browsing mode is enabled, the last download directory path is instead maintained in memory, and the preference is not changed.
When the user exits private browsing mode, the last download directory value is reverted to the preference's value.
When history is cleared
When the user's browsing history is cleared, the value of the last download directory path is restored to the platform's default download directory path.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论