Constructors(构造函数)
constructor
new URL(
url
, base?
)Parameters
Name | Type |
url | string |
base? |
Properties(属性)
hash
hash:
string
host
host:
string
hostname
hostname:
string
href
href:
string
origin
Readonly
origin: string
password
password:
string
pathname
pathname:
string
port
port:
string
protocol
protocol:
string
search
search:
string
searchParams
username
username:
string
Methods
setHash
setHash(
hash
): void
n设置网址的片段部分Parameters
Name | Type |
hash | string |
Returns:
void
setHost
setHost(
host
): void
n设置网址的主机部分Parameters
Name | Type |
host | string |
Returns:
void
setHostname
setHostname(
hostname
): void
n设置网址的主机名部分Parameters
Name | Type |
hostname | string |
Returns:
void
setHref
setHref(
href
): void
n设置序列化的网址Parameters
Name | Type |
href | string |
Returns:
void
setPassword
setPassword(
password
): void
n设置网址的密码部分Parameters
Name | Type |
password | string |
Returns:
void
setPathname
setPathname(
pathname
): void
n设置网址的路径部分Parameters
Name | Type |
pathname | string |
Returns:
void
setPort
setPort(
port
): void
n设置网址的端口部分Parameters
Name | Type |
port | string |
Returns:
void
setProtocol
setProtocol(
protocol
): void
n设置网址的协议部分Parameters
Name | Type |
protocol | string |
Returns:
void
setSearch
setSearch(
search
): void
n设置网址的序列化的查询部分Parameters
Name | Type |
search | string |
Returns:
void
setUsername
setUsername(
username
): void
n设置网址的用户名部分Parameters
Name | Type |
username | string |
Returns:
void
toJSON
toJSON():
string
Returns:string
toJSON():
string
n返回序列化的网址,当 URL 对象用 JSON.stringify() 序列化时,会自动调用此方法Returns:
string
toString
toString():
string
Returns:
string
toString():
string
n返回序列化的网址Returns:
string