Location.assign()

  • Revision slug: Web/API/Location.assign
  • Revision title: Location.assign()
  • Revision id: 463673
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ APIRef("Location") }}

The Location.assign()method loading the object at the URL providing in parameter.

If the assignment can't happen because of security restriction, a {{domxref("DOMException")}} of the SECURITY_ERROR type is thrown. This happens if the origin of the script calling the method is different from the origin of the page originally described by the Location object, mostly when the script is hosted on a different domain.

Syntax

object.assign(url);

Parameters

url
Is a {{domxref("DOMString")}} containing the URL of the page to navigate to.

Examples

// Navigate to the Location.reload article
document.location.assign('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "#dom-location-assign", "Location.assign")}} {{Spec2('HTML WHATWG')}} No change from {{SpecName("HTML5 W3C")}}.
{{SpecName('HTML5 W3C', "#dom-location-assign", "Location.assign()")}} {{Spec2('HTML5 W3C')}} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

See also

  • The {{domxref("Location")}} interface it belongs to.

Revision Source

<p>{{ APIRef("Location") }}</p>
<p>The <code><strong>Location</strong></code><strong><code>.assign()</code></strong>method loading the object at the URL providing in parameter.</p>
<p>If the assignment can't happen because of security restriction, a {{domxref("DOMException")}} of the <code>SECURITY_ERROR</code> type is thrown. This happens if the origin of the script calling the method is different from the origin of the page originally described by the <code>Location</code> object, mostly when the script is hosted on a different domain.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">
<em>object</em>.assign(<em>url</em>);
</pre>
<h3>Parameters</h3>
<dl>
  <dt>
    <em>url</em></dt>
  <dd>
    Is a {{domxref("DOMString")}} containing the URL of the page to navigate to.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<pre class="brush: js">
// Navigate to the Location.reload article
document.location.assign('https://developer.mozilla.org/en-US/docs/Web/API/Location.reload');</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('HTML WHATWG', "#dom-location-assign", "Location.assign")}}</td>
      <td>{{Spec2('HTML WHATWG')}}</td>
      <td>No change from {{SpecName("HTML5 W3C")}}.</td>
    </tr>
    <tr>
      <td>{{SpecName('HTML5 W3C', "#dom-location-assign", "Location.assign()")}}</td>
      <td>{{Spec2('HTML5 W3C')}}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Chrome for Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>The {{domxref("Location")}} interface it belongs to.</li>
</ul>
Revert to this revision