THE WORLD'S LARGEST WEB DEVELOPER SITE

Location hostname Property

❮ Location Object

Example

Return the hostname of the current URL:

var x = location.hostname;
Try it Yourself »

Definition and Usage

The hostname property sets or returns the hostname of a URL.


Browser Support

Property
hostname Yes Yes Yes Yes Yes

Syntax

Return the hostname property:

location.hostname

Set the hostname property:

location.hostname = hostname

Property Values

Value Type Description
hostname String Specifies the hostname of the URL

Technical Details

Return Value: A String, representing the domain name, or the IP address of a URL

❮ Location Object