English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Location hash property

JavaScript Location  Objekt

hashProperty sets or returns the anchor part of the URL, including the hash mark (#).

If the URL does not have a fragment identifier, this property returns an empty string "".

Note:When using this property to set the anchor part, do not include the hash mark (#).

Syntax:

Return hash property:

location.hash

Set Hash Property:

location.hash = anchorName
var anchor = document.getElementById("myAnchor");
document.querySelector("#output").innerHTML = anchor.hash;
Testen Sie heraus‹/›

Browserkompatibilität

hash-Eigenschaft wird von allen Browsern vollständig unterstützt:

Attribut
hashJaJaJaJaJa

Attributwert

WertBeschreibung
anchorNameEin String, der den Ankerbereich der URL spezifiziert

Technische Details

Rückgabewert:Ein String, der den Ankerbereich der URL darstellt, einschließlich des Hash-Symbols (#)

Mehr Beispiele

Ankerbereich festlegen:

var anchor = document.getElementById("myAnchor");
anchor.hash = "newFragement";
Testen Sie heraus‹/›

Verwandte Referenzen

Position Referenz:location.href-Eigenschaft

Position Referenz:location.hostname-Eigenschaft

Position Referenz:location.pathname-Eigenschaft

Position Referenz:location.protocol-Eigenschaft

JavaScript Location  Objekt