mozilla
Your Search Results

    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");
    

    Once you've imported the module, you can then use the gDownloadLastDir object it exports.

    Using the gDownloadLastDir object

    To determine or set the path into which the last download occurred:

    // file is an nsIFile
    var file = gDownloadLastDir.file;
    gDownloadLastDir.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
    gDownloadLastDir.setFile(uri, file);

    To retrieve the path in Firefox 26 or later, use getFileAsync:

    gDownloadLastDir.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

    Document Tags and Contributors

    Contributors to this page: Sheppy, teoli, adw, darktrojan
    Last updated by: adw,