Skip to main content

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.

MDN Reference

Methods​

toJSON()​

toJSON(): string;

The toJSON() method of the URL interface returns a string containing a serialized version of the URL, although in practice it seems to have the same effect as URL.toString().

MDN Reference

Returns​

string


toString()​

toString(): string;

Returns​

string

Properties​

hash​

hash: string;

The hash property of the URL interface is a string containing a "#" followed by the fragment identifier of the URL. If the URL does not have a fragment identifier, this property contains an empty string, "".

MDN Reference


host​

host: string;

The host property of the URL interface is a string containing the host, which is the hostname, and then, if the port of the URL is nonempty, a ":", followed by the port of the URL. If the URL does not have a hostname, this property contains an empty string, "".

MDN Reference


hostname​

hostname: string;

The hostname property of the URL interface is a string containing either the domain name or IP address of the URL. If the URL does not have a hostname, this property contains an empty string, "". IPv4 and IPv6 addresses are normalized, such as stripping leading zeros, and domain names are converted to IDN.

MDN Reference


href​

href: string;

The href property of the URL interface is a string containing the whole URL.

MDN Reference


origin​

readonly origin: string;

The origin read-only property of the URL interface returns a string containing the Unicode serialization of the origin of the represented URL.

MDN Reference


password​

password: string;

The password property of the URL interface is a string containing the password component of the URL. If the URL does not have a password, this property contains an empty string, "".

MDN Reference


pathname​

pathname: string;

The pathname property of the URL interface represents a location in a hierarchical structure. It is a string constructed from a list of path segments, each of which is prefixed by a / character.

MDN Reference


port​

port: string;

The port property of the URL interface is a string containing the port number of the URL. If the port is the default for the protocol (80 for ws: and http:, 443 for wss: and https:, and 21 for ftp:), this property contains an empty string, "".

MDN Reference


protocol​

protocol: string;

The protocol property of the URL interface is a string containing the protocol or scheme of the URL, including the final ":".

MDN Reference


search: string;

The search property of the URL interface is a search string, also called a query string, that is a string containing a "?" followed by the parameters of the URL. If the URL does not have a search query, this property contains an empty string, "".

MDN Reference


searchParams​

readonly searchParams: URLSearchParams;

The searchParams read-only property of the URL interface returns a URLSearchParams object allowing access to the GET decoded query arguments contained in the URL.

MDN Reference


username​

username: string;

The username property of the URL interface is a string containing the username component of the URL. If the URL does not have a username, this property contains an empty string, "".

MDN Reference