hostname属性设置或返回URL的主机名。
返回主机名属性:
location.hostname
设置主机名属性:
location.hostname = hostname
var x = location.hostname;
document.querySelector("#output").innerHTML = x;测试看看‹/›所有浏览器完全支持hostname属性:
| 属性 |  |  |  |  |  | 
| hostname | 是 | 是 | 是 | 是 | 是 | 
| 值 | 描述 | 
|---|---|
| hostname | 字符串,指定URL的主机名 | 
| 返回值: | 一个字符串,表示URL的域名或IP地址 | 
|---|
此示例显示所有位置属性:
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);测试看看‹/›
位置参考:location.href属性
位置参考:location.host属性
位置参考:location.pathname属性
位置参考:location.protocol属性