HTMLAreaElement: hostname プロパティ

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.

hostnameHTMLAreaElement インターフェイスのプロパティで、この <area> 要素の URL のドメイン名または IP アドレスのどちらかを含む文字列です。この URL にホスト名がない場合、このプロパティには空文字列 ("") が入ります。 IPv4 および IPv6 アドレスは、先頭の 0 が削除されるなど正規化され、ドメイン名は IDN に変換されます。

詳しくは URL.hostname を参照してください。

area 要素に関連付けられた URL のドメインを含む文字列です。 セッターとゲッターの両方として使用することができます。

<textarea id="log" rows="4" cols="100"></textarea>
<map name="infographic">
  <area
    id="area1"
    shape="rect"
    coords="184,6,253,27"
    href="/ja/docs/HTMLAreaElement"
    target="_blank"
    alt="Mozilla" />
  <area
    id="area2"
    shape="circle"
    coords="130,136,60"
    href="https://coolexample.com/"
    target="_blank"
    alt="MDN" />
</map>
// 要素が文書内にあったとします
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'

仕様書

Specification
HTML
# dom-hyperlink-hostname-dev

ブラウザーの互換性

関連情報