mozilla

Revision 463751 of History

  • Revision slug: Web/API/History
  • Revision title: History
  • Revision id: 463751
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

The History interface allows to manipulate the browser session history, that is the pages visited in the tab or frame that the current page is loaded in.

Properties

Property Type Description
length Integer Read-only. Returns the number of elements in the session history, including the currently loaded page. For example, for a page loaded in a new tab this property returns 1.
current {{ non-standard_inline() }} {{ obsolete_inline(26) }} String Returns the URL of the active item of the session history. This property is not available to web content and is not supported by other browsers. Use location.href instead.
next {{ non-standard_inline() }} {{ obsolete_inline(26) }} String Returns the URL of the next item in the session history. This property is not available to web content and is not supported by other browsers.
previous {{ non-standard_inline() }} {{ obsolete_inline(26) }} String Returns the URL of the previous item in the session history. This property is not available to web content and is not supported by other browsers.
state {{ gecko_minversion_inline("2.0") }} {{ interface("nsIVariant") }}

Returns the state at the top of the history stack. This is a way to look at the state without having to wait for a popstate event. Read only.

Methods

The History interface doesn't inherit any method.

{{domxref("History.back()")}}

Goes to the previous page in session history, the same action as when the user clicks the browser's Back button. Equivalent to history.go(-1).

Note: Calling this method to go back beyond the first page in the session history has no effect and doesn't raise an exception.
{{domxref("History.forward()")}}

Goes to the next page in session history, the same action as when the user clicks the browser's Forward button; this is equivalent to history.go(1).

Note: Calling this method to go back beyond the last page in the session history has no effect and doesn't raise an exception.
{{domxref("History.go()")}}
Loads a page from the session history, identified by its relative location to the current page, for example -1 for the previous page or 1 for the next page. When integerDelta is out of bounds (e.g. -1 when there are no previously visited pages in the session history), the method doesn't do anything and doesn't raise an exception. Calling go() without parameters or with a non-integer argument has no effect (unlike Internet Explorer, which supports string URLs as the argument).
{{domxref("History.pushState")}} {{ gecko_minversion_inline("2.0") }}

Pushes the given data onto the session history stack with the specified title and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized.  Note that Firefox currently ignores the title parameter; for more information, see manipulating the browser history.

Note: In Gecko 2.0 {{ geckoRelease("2.0") }} through Gecko 5.0 {{ geckoRelease("5.0") }}, the passed object is serialized using JSON. Starting in Gecko 6.0 {{ geckoRelease("6.0") }}, the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.
{{domxref("History.replaceState")}} {{ gecko_minversion_inline("2.0") }}

Updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized.  Note that Firefox currently ignores the title parameter; for more information, see manipulating the browser history.

Note: In Gecko 2.0 {{ geckoRelease("2.0") }} through Gecko 5.0 {{ geckoRelease("5.0") }}, the passed object is serialized using JSON. Starting in Gecko 6.0 {{ geckoRelease("6.0") }}, the object is serialized using the structured clone algorithm. This allows a wider variety of objects to be safely passed.

 

Revision Source

<p>The <strong><code>History</code></strong> interface allows to manipulate the browser <em>session history</em>, that is the pages visited in the tab or frame that the current page is loaded in.</p>
<h2>Properties</h2>
<table class="fullwidth-table">
  <tbody>
    <tr>
      <th>Property</th>
      <th>Type</th>
      <th>Description</th>
    </tr>
    <tr>
      <td><code id="length">length</code></td>
      <td>Integer</td>
      <td>Read-only. Returns the number of elements in the session history, including the currently loaded page. For example, for a page loaded in a new tab this property returns <code>1</code>.</td>
    </tr>
    <tr>
      <td><code id="current">current</code> {{ non-standard_inline() }} {{ obsolete_inline(26) }}</td>
      <td>String</td>
      <td>Returns the URL of the active item of the session history. This property is not available to web content and is not supported by other browsers. Use <code><a href="/en/DOM/window.location" title="en/DOM/window.location">location.href</a></code> instead.</td>
    </tr>
    <tr>
      <td><code id="next">next</code> {{ non-standard_inline() }} {{ obsolete_inline(26) }}</td>
      <td>String</td>
      <td>Returns the URL of the next item in the session history. This property is not available to web content and is not supported by other browsers.</td>
    </tr>
    <tr>
      <td><code id="previous">previous</code> {{ non-standard_inline() }} {{ obsolete_inline(26) }}</td>
      <td>String</td>
      <td>Returns the URL of the previous item in the session history. This property is not available to web content and is not supported by other browsers.</td>
    </tr>
    <tr>
      <td><code>state</code> {{ gecko_minversion_inline("2.0") }}</td>
      <td>{{ interface("nsIVariant") }}</td>
      <td>
        <p>Returns the state at the top of the history stack. This is a way to look at the state without having to wait for a <code>popstate</code> event. <strong>Read only.</strong></p>
      </td>
    </tr>
  </tbody>
</table>
<h2>Methods</h2>
<p><em>The <code>History</code></em> <em>interface doesn't inherit any method.</em></p>
<dl>
  <dt>
    {{domxref("History.back()")}}</dt>
  <dd>
    <p>Goes to the previous page in session history, the same action as when the user clicks the browser's Back button. Equivalent to <code>history.go(-1)</code>.</p>
    <div class="note">
      <strong>Note:</strong> Calling this method to go back beyond the first page in the session history has no effect and doesn't raise an exception.</div>
  </dd>
  <dt>
    {{domxref("History.forward()")}}</dt>
  <dd>
    <p>Goes to the next page in session history, the same action as when the user clicks the browser's Forward button; this is equivalent to <code>history.go(1)</code>.</p>
    <div class="note">
      <strong>Note:</strong> Calling this method to go back beyond the last page in the session history has no effect and doesn't raise an exception.</div>
  </dd>
  <dt>
    {{domxref("History.go()")}}</dt>
  <dd>
    Loads a page from the session history, identified by its relative location to the current page, for example <code>-1</code> for the previous page or <code>1</code> for the next page. When <code><em>integerDelta</em></code> is out of bounds (e.g. -1 when there are no previously visited pages in the session history), the method doesn't do anything and doesn't raise an exception. Calling <code>go()</code> without parameters or with a non-integer argument has no effect (unlike Internet Explorer, <a class="external" href="http://msdn.microsoft.com/en-us/library/ms536443(VS.85).aspx" title="http://msdn.microsoft.com/en-us/library/ms536443(VS.85).aspx">which supports string URLs as the argument</a>).</dd>
  <dt>
    {{domxref("History.pushState")}} {{ gecko_minversion_inline("2.0") }}</dt>
  <dd>
    <p>Pushes the given data onto the session history stack with the specified title and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized.&nbsp; Note that Firefox currently ignores the title parameter; for more information, see <a href="/en/DOM/Manipulating_the_browser_history" title="en/DOM/Manipulating the browser history">manipulating the browser history</a>.</p>
    <div class="note">
      <strong>Note:</strong> In Gecko 2.0 {{ geckoRelease("2.0") }} through Gecko 5.0 {{ geckoRelease("5.0") }}, the passed object is serialized using JSON. Starting in Gecko 6.0 {{ geckoRelease("6.0") }}, the object is serialized using <a href="/en/DOM/The_structured_clone_algorithm" title="en/DOM/The structured clone algorithm">the structured clone algorithm</a>. This allows a wider variety of objects to be safely passed.</div>
  </dd>
  <dt class="note">
    {{domxref("History.replaceState")}} {{ gecko_minversion_inline("2.0") }}</dt>
  <dd>
    <p>Updates the most recent entry on the history stack to have the specified data, title, and, if provided, URL. The data is treated as opaque by the DOM; you may specify any JavaScript object that can be serialized.&nbsp; Note that Firefox currently ignores the title parameter; for more information, see <a href="/en/DOM/Manipulating_the_browser_history" title="en/DOM/Manipulating the browser history">manipulating the browser history</a>.</p>
    <strong>Note:</strong> In Gecko 2.0 {{ geckoRelease("2.0") }} through Gecko 5.0 {{ geckoRelease("5.0") }}, the passed object is serialized using JSON. Starting in Gecko 6.0 {{ geckoRelease("6.0") }}, the object is serialized using <a href="/en/DOM/The_structured_clone_algorithm" title="en/DOM/The structured clone algorithm">the structured clone algorithm</a>. This allows a wider variety of objects to be safely passed.</dd>
</dl>
<p>&nbsp;</p>
Revert to this revision