此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLAnchorElement:username 属性

基线 广泛可用

自 2020年1月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

HTMLAnchorElement.username 属性是一个字符串,包含在域名之前指定的用户名。

一个字符串。

示例

从锚点链接中获取用户名

js
// 假设文档中含有这样的元素:<a id="myAnchor" href="https://anonymous:flabada@developer.mozilla.org/zh-CN/docs/HTMLAnchorElement">
const anchor = document.getElementByID("myAnchor");
anchor.username; // 返回“anonymous”

规范

规范
HTML
# dom-hyperlink-username-dev

浏览器兼容性

参见