pathname属性设置或返回一个URL的路径名。
路径名是一个字符串,该字符串以主机名开头,包含一个初始的“/”,后跟URL的路径。
返回路径名属性:
location.pathname
设置路径名属性:
location.pathname = path
var x = location.pathname;
document.querySelector("#output").innerHTML = x;测试看看‹/›所有浏览器完全支持pathname属性:
| 属性 |  |  |  |  |  | 
| pathname | 是 | 是 | 是 | 是 | 是 | 
| 值 | 描述 | 
|---|---|
| path | 字符串,指定URL的路径 | 
| 返回值: | 字符串,表示URL的路径;如果没有路径,则为空字符串 | 
|---|
此示例显示所有位置属性:
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.origin属性
位置参考:location.protocol属性