URLPattern: hostname 屬性
注意:此功能在 Web Workers 中可用。
URLPattern 介面的 hostname 只讀屬性是一個字串,其中包含用於匹配 URL 主機名部分的模式。
這是傳遞給建構函式的 hostname 模式的標準化值,從傳遞給建構函式的 baseURL 繼承的值,或者預設值 ("*"),它匹配任何主機名。
值
字串。
示例
基本用法
以下示例建立一個 URLPattern 物件,其中 hostname 部分為 *.example.org,並記錄該屬性。此模式匹配 example.org 的任何直接子域的 hostname。
js
const pattern = new URLPattern("https://*.example.org");
console.log(pattern.hostname); // '*.example.org'
console.log(pattern.test("https://horses.example.org")); // true
規範
| 規範 |
|---|
| URL 模式 # dom-urlpattern-hostname |
瀏覽器相容性
載入中…