Window location.hostname
Definition and Usage
The location.hostname
property
returns the host (IP adress or domain) of a URL.
The location.hostname
property
can also be set, to navigate to the same URL with a new hostname.
Syntax
Return the hostname property:
location.hostname
Set the hostname property:
location.hostname = hostname
Property Value
Value | Description |
hostname | The hostname of the URL. |
Return Value
Type | Description |
A string | The host (IP address or domain) of a URL. |
Browser Support
location.hostname
is supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |