Window location.pathname
实例
获取当前路径:
<!DOCTYPE html><html><body><h2>pathname 属性</h2><p id="demo"><script>let path = location.pathname;document.getElementById("demo").innerHTML = path;</script></body></html>
定义与用法
pathname 属性设置或返回 URL(页面)的路径名。
语法
返回 pathname 属性:
location.pathname
设置 pathname 属性:
location.pathname = path
Property Values
| 参数 | 描述 |
| path | URL 的路径名 |
返回值
| 类型 | 描述 |
| A string | 当前路径名。 |
浏览器支持
location.pathname 所有浏览器都支持:
| 属性 | |||||
|---|---|---|---|---|---|
| location.pathname | Yes | Yes | Yes | Yes | Yes |