location: assign() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Location.assign() メソッドは、指定された URL の文書をウィンドウに読み込んで表示します。移動した後、ユーザーは「戻る」ボタンを押すことによって Location.assign() を呼び出したページに戻ることができます。

セキュリティ違反のために代入ができない場合は、 DOMExceptionSECURITY_ERROR 型で発生します。これは、メソッドを呼び出すスクリプトのオリジンが、 Location オブジェクトによって元々記述されていたページのオリジンと異なる場合に起こります。主に、スクリプトが異なるドメインでホストされている場合に起こります。

指定された URL が有効でない場合、 DOMExceptionSYNTAX_ERROR 型で発生します。

構文

js
assign(url)

引数

url

文字列で、移動先のページの URL です。

返値

なし (undefined)。

js
// Location.reload の記事へ移動
window.location.assign(
  "https://developer.mozilla.org/ja/docs/Web/API/Location/reload",
);

仕様書

Specification
HTML
# dom-location-assign-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
assign

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
User must explicitly enable this feature.

関連情報