DownloadLastDir.jsm

  • Revision slug: JavaScript_code_modules/DownloadLastDir.jsm
  • Revision title: DownloadLastDir.jsm
  • Revision id: 80629
  • Created:
  • Creator: darktrojan
  • Is current revision? No
  • Comment 79 words added, 25 words removed

Revision Content

{{ gecko_minversion_header("2.0") }}

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:

// path is an nsIFile
var path = gDownloadLastDir.file;
gDownloadLastDir.file = path;

You can also retrieve or set this information on a site-by-site basis. To do this, use the getFile or setFile methods:

// path is an nsIFile, uri is an nsIURI object or a string
var path = gDownloadLastDir.getFile(uri);
gDownloadLastDir.setFile(uri, path);

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

Revision Source

<p>{{ gecko_minversion_header("2.0") }}</p>
<p>The <code>DownloadLastDir.jsm</code> JavaScript code module lets you retrieve the path of the last directory into which a download occurred.</p>
<p>To use this, you first need to import the code module into your JavaScript scope:</p>
<pre>Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
</pre>
<p>Once you've imported the module, you can then use the <code>gDownloadLastDir</code> object it exports.</p>
<h2>Using the gDownloadLastDir object</h2>
<p>To determine or set the path into which the last download occurred:</p>
<pre class="brush: js">// path is an nsIFile
var path = gDownloadLastDir.file;
gDownloadLastDir.file = path;
</pre>
<p>You can also retrieve or set this information on a site-by-site basis. To do this, use the <code>getFile</code> or <code>setFile</code> methods:</p>
<pre class="brush: js">// path is an nsIFile, uri is an nsIURI object or a string
var path = gDownloadLastDir.getFile(uri);
gDownloadLastDir.setFile(uri, path);
</pre>
<h2>Private browsing mode</h2>
<p>When browsing normally, the browser uses the <code>browser.download.lastDir</code> 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.</p>
<p>When the user exits private browsing mode, the last download directory value is reverted to the preference's value.</p>
<h2>When history is cleared</h2>
<p>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.</p>
<h2>See also</h2>
<ul> <li><a class="internal" href="/en/JavaScript_code_modules/Using" title="en/JavaScript code modules/Using JavaScript code modules">Using JavaScript code modules</a></li> <li><a class="internal" href="/en/JavaScript_code_modules" title="en/JavaScript code modules">JavaScript code modules</a></li>
</ul>
Revert to this revision