目录

window location.pathname

示例

获取当前路径:

let path x = location.pathname;
亲自试一试 »

描述

这个pathname属性设置或返回 URL(页面)的路径名。


语法

返回路径名属性:

location.pathname

设置路径名属性:

location.pathname = path

属性值

Parameter Description
path The pathname of the URL.

返回值

类型 描述
一个字符串 当前路径名。

浏览器支持

location.pathname所有浏览器都支持:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes