Location: hostname

The hostname property of the Location interface is a USVString containing the domain of the URL.

Syntax

string = object.hostname;
object.hostname = string;

Examples

// Let's an <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/Location.hostname"> element be in the document
var anchor = document.getElementById("myAnchor");
var result = anchor.hostname; // Returns:'developer.mozilla.org'

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'hostname' in that specification.
Living Standard Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
hostnameChrome Full support YesEdge Full support 12Firefox Full support 22IE Full support YesOpera No support NoSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 22Opera Android No support NoSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support