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

浏览器兼容性