Window location.host
Definition and Usage
The location.host
property
returns the host (IP adress or domain) and port of a URL.
The location.host
property
can also be set, to navigate to the same URL with a new host and port.
Note
If the port number is not specified in the URL, or if it is a default port (80 for http) or (443 for https), most browsers will return an empty string.
See Also:
Syntax
Return the host property:
location.host
Set the host property:
location.host = host:port
Property Value
Value | Description |
host:port | The host and port number of the URL. |
Return Value
Type | Description |
A string | The host (IP address or domain) and port number of a URL. |
Browser Support
location.host
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |