Location: hash
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
接口的 hash
属性返回一个 USVString
,其中会包含 URL 标识中的 '#'
和 后面 URL 片段标识符。
这里 fragment 不会经过百分比编码(URL 编码)。如果 URL 中没有 fragment,该属性会包含一个空字符串,""
Syntax
string = object.hash; object.hash = string;
Examples
html
<a id="myAnchor" href="/zh-CN/docs/Location.href#Examples">Examples</a>
<script>
var anchor = document.getElementById("myAnchor");
console.log(anchor.hash); // 返回'#Examples'
</script>
Specifications
Specification |
---|
HTML Standard # dom-location-hash-dev |
Browser compatibility
BCD tables only load in the browser