Window location.hostname attribute

Definition and usage

location.hostname attribute to return the host of the URL (IP address or domain name).

You can also set location.hostname Navigate to the same URL with a new hostname attribute.

See also:

location.host attribute

Example

Return the hostname of the current URL:

let hostname = location.hostname;

Try it yourself

Syntax

Return hostname attribute:

location.hostname

Set hostname attribute:

location.hostname = hostname

Attribute value

Value Description
hostname The hostname of the URL.

Return value

Type Description
String The host of the URL (IP address or domain name).

Browser Support

All Browsers Support location.hostname:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support