HTMLAreaElement: hash 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

HTMLAreaElement 介面的 hash 屬性是一個字串,包含一個 "#" 字元,後跟 <area> 元素的 href 的片段識別符號。如果 URL 沒有片段識別符號,則此屬性包含一個空字串 ""

有關更多資訊,請參閱 URL.hash

字串。

示例

給定此 HTML

html
<map name="infographic">
  <area
    id="mdn-circle"
    shape="circle"
    coords="130,136,60"
    href="https://mdn.club.tw/#ExampleSection"
    alt="MDN" />
</map>

<img
  usemap="#infographic"
  src="/media/examples/mdn-info.png"
  alt="MDN infographic" />

您可以像這樣獲取 area 連結的 hash:

js
const area = document.getElementById("mdn-circle");
area.hash; // '#ExampleSection'

規範

規範
HTML
# dom-hyperlink-hash-dev

瀏覽器相容性

另見