Class: URL

为未提供 Web URL API 的 JavaScriptCore 环境提供 URL polyfill。

A URL polyfill for JavaScriptCore environments that do not provide the Web URL API.

Constructors

Constructor

new URL(url, base?): URL

使用绝对 URL,或相对 URL 与基础 URL 创建 URL 实例。

Creates a URL from an absolute URL string or a relative URL with a base.

Parameters

url

string

要解析的绝对或相对 URL。
The absolute or relative URL to parse.

base?

string

用于解析相对 URL 的绝对基础 URL。
The absolute base URL used to resolve a relative URL.

Returns

URL

Accessors

hash

Get Signature

get hash(): string

URL 片段;存在时包含开头的 #
The URL fragment, including the leading # when present.

Returns

string

Set Signature

set hash(value): void

Parameters
value

string

Returns

void


host

Get Signature

get host(): string

URL 的主机名与端口。
The hostname and port of the URL.

Returns

string

Set Signature

set host(value): void

Parameters
value

string

Returns

void


hostname

Get Signature

get hostname(): string

URL 编码后的主机名。
The encoded hostname of the URL.

Returns

string

Set Signature

set hostname(value): void

Parameters
value

string

Returns

void


href

Get Signature

get href(): string

完整序列化后的 URL。
The complete serialized URL.

Returns

string

Set Signature

set href(value): void

Parameters
value

string

Returns

void


origin

Get Signature

get origin(): string

由协议与主机组成的序列化源。
The serialized origin, consisting of the protocol and host.

Returns

string


password

Get Signature

get password(): string

主机名前指定的编码后密码。
The encoded password specified before the host.

Returns

string

Set Signature

set password(value): void

Parameters
value

string

Returns

void


pathname

Get Signature

get pathname(): string

URL 路径,包含开头的 /
The URL path, including the leading /.

Returns

string

Set Signature

set pathname(value): void

Parameters
value

string

Returns

void


port

Get Signature

get port(): string

显式端口;使用协议默认端口时为空字符串。
The explicit port, or an empty string for the protocol's default port.

Returns

string

Set Signature

set port(value): void

Parameters
value

string

Returns

void


protocol

Get Signature

get protocol(): string

URL 协议,包含结尾的 :
The URL scheme, including the trailing :.

Returns

string

Set Signature

set protocol(value): void

Parameters
value

string

Returns

void


Get Signature

get search(): string

序列化后的查询字符串;存在时包含开头的 ?
The serialized query string, including the leading ? when present.

Returns

string

Set Signature

set search(value): void

Parameters
value

string

Returns

void


searchParams

Get Signature

get searchParams(): URLSearchParams

URL 查询参数的可变视图。
A mutable view of the URL query parameters.

Returns

URLSearchParams


username

Get Signature

get username(): string

主机名前指定的编码后用户名。
The encoded username specified before the host.

Returns

string

Set Signature

set username(value): void

Parameters
value

string

Returns

void

Methods

toJSON()

toJSON(): string

将 URL 对象的公开属性转换为 JSON 字符串。

Converts the URL object properties to a JSON string.

Returns

string

包含 URL 公开属性的 JSON 字符串。
A JSON string containing the public URL properties.


toString()

toString(): string

返回 URL 的字符串表示。

Returns the string representation of the URL.

Returns

string

完整序列化后的 URL。
The complete serialized URL.


parse()

static parse(url, base?): URL

使用与构造函数相同的输入解析 URL。

Parses a URL using the same inputs accepted by the constructor.

Parameters

url

string

要解析的绝对或相对 URL。
The absolute or relative URL to parse.

base?

string

用于解析相对 URL 的绝对基础 URL。
The absolute base URL used to resolve a relative URL.

Returns

URL

解析得到的 URL 实例。
A parsed URL instance.