URL.hostname

URL 接口的 hostname 属性是一个 USVString 值,包含有 URL 中的域名。

备注: 此特性在 Web Worker 中可用。

语法

string = object.hostname;
object.hostname = string;

返回值

示例

js
var url = new URL(
  "https://developer.mozilla.org/zh-CN/docs/Web/API/URL/hostname",
);
var result = url.hostname; // Returns:'developer.mozilla.org'

规范

Specification
URL Standard
# dom-url-hostname

浏览器兼容性

BCD tables only load in the browser

参考

  • 属的 URL 接口。