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 |
浏览器兼容性
加载中…