HTMLAreaElement: hostname 屬性

Baseline 已廣泛支援

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

HTMLAreaElement 介面的 hostname 屬性是一個字串,包含 <area> 元素的 URL 的 域名IP 地址。如果 URL 沒有主機名,則此屬性包含一個空字串 ""。IPv4 和 IPv6 地址會被規範化,例如去除前導零,域名會被轉換為 IDN

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

一個字串,包含與 area 元素關聯的 URL 的域名。它既可以用作 setter,也可以用作 getter。

示例

html
<textarea id="log" rows="4" cols="100"></textarea>
<map name="infographic">
  <area
    id="area1"
    shape="rect"
    coords="184,6,253,27"
    href="/en-US/docs/HTMLAreaElement"
    target="_blank"
    alt="Mozilla" />
  <area
    id="area2"
    shape="circle"
    coords="130,136,60"
    href="https://coolexample.com/"
    target="_blank"
    alt="MDN" />
</map>
js
// An element is in the document
const area1 = document.getElementById("area1");
const area2 = document.getElementById("area2");

const log = document.getElementById("log");
log.textContent = `area1 hostname: ${area1.hostname} \n`; // 'developer.mozilla.org'
log.textContent += `area2 hostname: ${area2.hostname}`; // 'coolexample.com'

規範

規範
HTML
# dom-hyperlink-hostname-dev

瀏覽器相容性

另見