URLPattern:protocol 屬性
注意:此功能在 Web Workers 中可用。
protocol 是 URLPattern 介面的一個只讀屬性,它返回一個字串,包含用於匹配 URL 協議部分的模式。
這是傳遞給建構函式的協議模式的規範化值,或者是傳遞給建構函式的從 baseURL 繼承的值,或者是預設值 ("*"),該預設值匹配任何協議。
值
字串。
示例
基本用法
以下示例建立一個 URLPattern 物件,其中 protocol 部分使用 http{s}? 模式,並列印該屬性。此模式匹配任何具有 http 或 https 協議的 URL。
js
const pattern = new URLPattern({ protocol: "http{s}?" });
console.log(pattern.protocol); // 'http{s}?'
console.log(pattern.test("https://example.com/shoes?q=baby")); // true
規範
| 規範 |
|---|
| URL 模式 # dom-urlpattern-protocol |
瀏覽器相容性
載入中…