pathname 特性为 定位 接口是 USVString 包含初始 '/' followed by the path of the URL (or the empty string if there is no path).

句法

string = object.pathname;
object.pathname = string;
					

范例

// Let's an <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/Location.pathname"> element be in the document
var anchor = document.getElementById("myAnchor");
var result = anchor.pathname; // Returns:'/en-US/docs/Location.pathname'
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'pathname' in that specification.
实时标准 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
pathname Chrome Yes Edge 12 Firefox 22
22
Before Firefox 53, the pathname property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" rather than "/x".
IE Yes
Yes
Internet Explorer does not provide the leading slash character in the pathname ( docs/Web/API/Location 而不是 /docs/Web/API/Location ).
Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 22
22
Before Firefox 53, the pathname property returned wrong parts of the URL. For example, for a URL of http://z.com/x?a=true&b=false, pathname would return "/x?a=true&b=false" rather than "/x".
Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

见实现注意事项。

元数据

  • 最后修改:
  1. 定位
  2. 特性
    1. Location: ancestorOrigins
    2. Location: hash
    3. Location: host
    4. Location: hostname
    5. Location: href
    6. Location: origin
    7. Location: password
    8. Location: pathname
    9. Location: port
    10. Location: protocol
    11. Location: search
    12. Location: username
  3. 方法
    1. Location: assign()
    2. Location: reload()
    3. Location: replace()
    4. Location: toString()

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1