Window location.hostname

Example

Return the hostname of the current URL:

let hostname = location.hostname;
Try it Yourself »

Description

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 stringThe host (IP address or domain) of a URL.

Browser Support

location.hostname is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.