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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:80 次

字数:2928

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文