location: href プロパティ

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.

hrefLocation インターフェイスのプロパティで、文字列化です。文字列で URL 全体を表し、href を更新することができます。

href の値を設定すると、指定された URL に移動します。もし、redirection が欲しい場合は、location.replace()を使用してください。href プロパティ値の設定との違いは、 location.replace() メソッドを使用した場合、指定した URL に移動した後、現在のページはセッションの履歴に保存されないことです - つまりユーザーは戻るボタンで移動することはできません。

文字列

文字列です。

js
// 文書内に <a id="myAnchor" href="/ja/docs/Location/href"> 要素があるとする
const anchor = document.getElementById("myAnchor");
const result = anchor.href; // Returns: 'https://developer.mozilla.org/ja/Location/href'

仕様書

Specification
HTML
# dom-location-href-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
href

Legend

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

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