location.href
href
は Location
インターフェイスのプロパティで、文字列化であり、 USVString
で URL 全体を表し、 href を更新することができます。
href
の値を設定すると、指定された URL に移動します。もし、_redirection_が欲しい場合は、location.replace()
を使用してください。href
プロパティ値の設定との違いは、 location.replace()
メソッドを使用した場合、指定した URL に移動した後、現在のページはセッション history に保存されないことです - つまりユーザーは戻るボタンで移動することはできません。
構文
string = object.href;
object.href = string;
例
// Lets imagine an <a id="myAnchor" href="https://developer.mozilla.org/ja/Location/href"> element is in the document
var anchor = document.getElementById("myAnchor");
var result = anchor.href; // Returns: 'https://developer.mozilla.org/ja/Location/href'
仕様書
Specification |
---|
HTML Standard # dom-location-href-dev |
ブラウザーの互換性
BCD tables only load in the browser