Revision 108668 of openLocationLastURL.jsm

  • Revision slug: JavaScript_code_modules/openLocationLastURL.jsm
  • Revision title: openLocationLastURL.jsm
  • Revision id: 108668
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment clean up; 2 words added, 2 words removed

Revision Content

{{ gecko_minversion_header("1.9.1.4") }}

The openLocationLastURL.jsm JavaScript code module lets you set and retrieve the URL most recently opened using the "Open Location" option in the File menu.

To use this, you first need to import the code module into your JavaScript scope:

Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

Once you've imported the module, you can then use the gOpenLocationLastURL object it exports. This object lets you fetch and change the URL that is placed in the "Open Location" dialog box when it opens.

If the user is not in private browsing mode, this automatically updates the value of the general.open_location.last_url preference.

Note: This module automatically handles private browsing mode for you. The value preserved across accesses is not preserved when the user exits private browsing mode.

Using the gOpenLocationLastURL object

To get or set the value of the Open Location edit box, simply read the value of, or set the value of, the gOpenLocationLastURL.value field:

var url = gOpenLocationLastURL.value;

gOpenLocationLastURL.value = "http://www.mozilla.org/"; 

To reset the value of the edit box to the default (which is an empty string), you can call the reset() method:

Method overview

reset()

Methods

reset

The reset() method resets the saved URL to the default, which is an empty string.

reset();
Parameters

None.

See also

Revision Source

<p>{{ gecko_minversion_header("1.9.1.4") }}</p>
<p>The <code>openLocationLastURL.jsm</code> JavaScript code module lets you set and retrieve the URL most recently opened using the "Open Location" option in the File menu.</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/XPCOMUtils.jsm");
</pre>
<p>Once you've imported the module, you can then use the <code>gOpenLocationLastURL</code> object it exports. This object lets you fetch and change the URL that is placed in the "Open Location" dialog box when it opens.</p>
<p>If the user is not in private browsing mode, this automatically updates the value of the <code>general.open_location.last_url</code> preference.</p>
<div class="note"><strong>Note:</strong> This module automatically handles private browsing mode for you. The value preserved across accesses is not preserved when the user exits private browsing mode.</div>
<h2 id="Using_the_gOpenLocationLastURL_object">Using the gOpenLocationLastURL object</h2>
<p>To get or set the value of the Open Location edit box, simply read the value of, or set the value of, the <code>gOpenLocationLastURL.value</code> field:</p>
<pre class="brush: js">var url = gOpenLocationLastURL.value;

<span class="plain">gOpenLocationLastURL.value = "http://www.mozilla.org/"; </span>
</pre>
<p>To reset the value of the edit box to the default (which is an empty string), you can call the <a class="internal" href="/en/JavaScript/Code_modules/openLocationLastURL.jsm#reset()" title="en/JavaScript code modules/openLocationLastURL.jsm#reset()"><code>reset()</code></a> method:</p>
<h2 id="Method_overview">Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code>reset()</code></td> </tr> </tbody>
</table>
<h2 id="Methods">Methods</h2>
<h3 id="reset">reset</h3>
<p>The <span style="font-family: monospace;">reset</span><code>()</code> method resets the saved URL to the default, which is an empty string.</p>
<pre>reset();
</pre>
<h6 id="Parameters">Parameters</h6>
<p>None.</p>
<h2 id="See_also">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