URLPattern: hostname property

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.

Note: This feature is available in Web Workers.

Thuộc tính chỉ đọc hostname của giao diện URLPattern là một chuỗi chứa mẫu được dùng để khớp phần hostname của một URL.

Đây là giá trị đã chuẩn hóa của mẫu hostname được truyền cho hàm tạo, một giá trị được kế thừa từ baseURL được truyền cho hàm tạo, hoặc giá trị mặc định ("*"), khớp với mọi hostname.

Giá trị

Một chuỗi.

Ví dụ

Cách dùng cơ bản

Ví dụ sau tạo một đối tượng URLPattern với *.example.org cho phần hostname và ghi lại thuộc tính. Mẫu này khớp với bất kỳ hostname nào là một miền con trực tiếp của 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

Đặc tả

Specification
URL Pattern
# dom-urlpattern-hostname

Tương thích trình duyệt