URLPattern: hostname プロパティ
Baseline
2025
Newly available
Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
メモ: この機能はウェブワーカー内で利用可能です。
hostname は URLPattern インターフェイスの読み取り専用プロパティで、URL のホスト名部分と照合するパターンを含む文字列です。
この値は、コンストラクターに渡されたホスト名のパターンの正規化値、 コンストラクターに渡された baseURL からの継承値、任意のホスト名に一致するデフォルト値 ("*") のいずれかです。
値
文字列です。
例
>基本的な使い方
下記の例では URLPattern オブジェクトを作成し、 *.example.org を hostname 部分として指定しています。このパターンは、example.org の直接のサブドメインであるホスト名すべてに一致します。
js
const pattern = new URLPattern("https://*.example.org");
console.log(pattern.hostname); // '*.example.org'
console.log(pattern.test("https://horses.example.org")); // true
仕様書
| Specification |
|---|
| URL Pattern> # dom-urlpattern-hostname> |