URLPattern: password 屬性

基準線 2025
新推出

自 ⁨2025 年 9 月⁩起,此功能適用於最新裝置和瀏覽器版本。此功能可能不適用於較舊的裝置或瀏覽器。

注意:此功能在 Web Workers 中可用。

URLPattern 介面的 password 只讀屬性是一個字串,其中包含用於匹配 URL 密碼部分的模式

這是傳遞給 建構函式 的密碼模式的規範化值,或者是預設值 ("*"),它匹配任何密碼。

字串。

示例

基本用法

以下示例建立一個 URLPattern 物件,其 password 部分為 correct-horse-battery{-staple}?,並記錄該屬性。此模式匹配密碼 correct-horse-batterycorrect-horse-battery-staple

js
const pattern = new URLPattern({ password: "correct-horse-battery{-staple}?" });
console.log(pattern.password); // 'correct-horse-battery{-staple}?'
console.log(pattern.test("https://user:correct-horse-battery@example.com")); // true

規範

規範
URL 模式
# dom-urlpattern-password

瀏覽器相容性