URLPattern:port 屬性
注意:此功能在 Web Workers 中可用。
port 是 URLPattern 介面的一個只讀屬性,它包含用於匹配 URL 埠部分的模式字串。
它是傳遞給 建構函式的埠模式的規範化值,或者是傳遞給建構函式的從 baseURL 繼承的值,或者是預設值 ("*"),該預設值匹配任何埠。
請注意,如果使用 url 或 baseURL 字串指定模式且未明確設定埠,它也可能被隱式設定為空字串 ("")。這個空字串匹配使用預設埠 (443) 的 URL。
值
字串。
示例
基本用法
以下示例建立了一個 URLPattern 物件,其 port 部分為 (80|443|8080),並記錄了該屬性。此模式匹配埠為 80、443 或 8080 的任何 URL。
js
const pattern = new URLPattern({ port: "(80|443|8080)" });
console.log(pattern.port); // "(80|443|8080)"
console.log(pattern.test("http://example.com:8080/")); // true
規範
| 規範 |
|---|
| URL 模式 # dom-urlpattern-port |
瀏覽器相容性
載入中…