URL
The URL
interface is used to parse, construct, normalize, and encode URLs.
It works by providing properties which allow you to easily read and modify
the components of a URL.
You normally create a new URL
object by specifying the URL as a string
when calling its constructor, or by providing a relative URL and a base
URL. You can then easily read the parsed components of the URL or make
changes to the URL.
Implements
Constructors
new URL()
new URL(url
, base
?): URL
Constructs a new URL object by parsing the specified URL.
Parameters
Parameter | Type | Description |
---|---|---|
url | string | URL | The input URL to be parsed. |
base ? | string | URL | The base URL to use in case the input URL is a relative URL. |
Returns
Properties
Property | Modifier | Type | Description |
---|---|---|---|
hash | public | string | MDN Reference |
host | public | string | MDN Reference |
hostname | public | string | MDN Reference |
href | public | string | MDN Reference |
origin | readonly | string | MDN Reference |
password | public | string | MDN Reference |
pathname | public | string | MDN Reference |
port | public | string | MDN Reference |
protocol | public | string | MDN Reference |
search | public | string | MDN Reference |
username | public | string | MDN Reference |
Accessors
searchParams
get
searchParams(): URLSearchParams
Returns
Implementation of
globalThis.URL.searchParams
Methods
toJSON()
toJSON(): string
Returns a string containing the full URL. It is a synonym for the href
property.
Returns
string
Implementation of
globalThis.URL.toJSON
toString()
toString(): string
Returns a string containing the full URL. It is a synonym for the href
property, though it can't be used to modify the value.
Returns
string
Implementation of
globalThis.URL.toString
canParse()
static
canParse(url
, base
?): void
Returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid.
Parameters
Parameter | Type | Description |
---|---|---|
url | string | URL | The input URL to be parsed. |
base ? | string | URL | The base URL to use in case the input URL is a relative URL. |
Returns
void
See
https://developer.mozilla.org/docs/Web/API/URL/canParse_static
createObjectURL()
static
createObjectURL(obj
): string
Returns a string containing a URL which represents the provided Blob
object.
Parameters
Parameter | Type | Description |
---|---|---|
obj | Blob | The object for which an object URL is to be created. |
Returns
string
See
https://developer.mozilla.org/docs/Web/API/URL/createObjectURL_static
revokeObjectURL()
static
revokeObjectURL(url
): void
Revokes an object URL previously created using URL.createObjectURL()
.
Parameters
Parameter | Type | Description |
---|---|---|
url | string | A string representing a URL that was created by calling URL.createObjectURL() . |
Returns
void
See
https://developer.mozilla.org/docs/Web/API/URL/revokeObjectURL_static