window.location.host
Summary
The host property contains the host part of the the current document URL, (hostname:port).
Property of apis/locationapis/location
Syntax
Note: This property is read-only.
var result = window.location.host;
Return Value
Returns an object of type StringString
The hostname and port number.
For example, http://example.org:8080/
would return the host string of example.org:8080
.
Examples
The following example assumes your document has a div element with id 'hostDiv’, like this.
// Get the host from window.location
var host = window.location.host;
// Get a div element with id 'hostDiv'
var container = document.getElementById('hostDiv');
// Fill in the div element with the host
container.innerHTML = host;
Related specifications
- Window Object 1.0
- W3C Working Draft