English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
hostnameSets or returns the hostname of the URL.
Return the hostname attribute:
location.hostname
Set the hostname attribute:
location.hostname = hostname
var x = location.hostname; document.querySelector("#output").innerHTML = x;Test and See‹/›
All browsers fully support the hostname attribute:
Attribute | |||||
hostname | Is | Is | Is | Is | Is |
Value | Description |
---|---|
hostname | A string that specifies the hostname of the URL |
Return value: | A string representing the domain name or IP address of the URL |
---|
This example shows all location attributes:
var txt = ""; txt += "<p>Host: " + location.host + "</p>"; txt += "<p>Hostname: " + location.hostname + "</p>"; txt += "<p>Href: " + location.href + "</p>"; txt += "<p>Origin: " + location.origin + "</p>"; txt += "<p>Pathname: " + location.pathname + "</p>"; txt += "<p>Protocol: " + location.protocol + "</p>"; txt += "<p>Search: " + location.search + "</p>"; document.write(txt);Test and See‹/›
Location Reference:location.href property
Location Reference:location.host property
Location Reference:location.pathname property
Location Reference:location.protocol property