URL
Browser-compatible URL class, implemented by following the WHATWG URL Standard. Examples of parsed URLs may be found in the Standard itself.
Instance Members
hash: String
Gets and sets the fragment portion of the URL.
host: String
Gets and sets the host portion of the URL.
hostname: String
Gets and sets the hostname portion of the URL
The key difference between url.host
and url.hostname
is that url.hostname
does not include the port.
href: String
Gets and sets the serialized URL.
origin: String
Gets the read-only serialization of the URL's origin.
password: String
Gets and sets the password portion of the URL.
pathname: String
Gets and sets the path portion of the URL.
port: String
Gets and sets the port portion of the URL.
The port value may be a number or a string containing a number in the range 0
to 65535
(inclusive).
Setting the value to the default port of the URL
objects given protocol
will result in the port value becoming the empty string (''
).
protocol: String
Gets and sets the protocol portion of the URL.
search: String
Gets and sets the serialized query portion of the URL.
searchParams: URLSearchParams
Gets the URLSearchParams
object representing the query parameters of the URL.
This property is read-only; to replace the entirety of query parameters of the URL, use the url.search
setter.
See URLSearchParams documentation for details.
username: String
Gets and sets the username portion of the URL.
toString(): String
The toString()
method on the URL
object returns the serialized URL.
The value returned is equivalent to that of url.href
and url.toJSON()
.
Because of the need for standard compliance, this method does not allow users to customize the serialization process of the URL.
For more flexibility, require('url').format()
method might be of interest.
Returns |
---|
String |
toJSON(): String
The toJSON()
method on the URL
object returns the serialized URL.
The value returned is equivalent to that of url.href
and url.toString()
.
This method is automatically called when an URL
object is serialized with JSON.stringify()
.
Returns |
---|
String |
Creates a new URL
object by parsing the input
relative to the base
.
If base
is passed as a string, it will be parsed equivalent to new URL(base)
.
Name | Type | Default |
---|---|---|
input |
String | |
base |
String | (optional) |
Metadata
Name | Parameters |
---|---|
:jsRequire |
"url", "URL" |