--- title: 'Location: hostname' slug: Web/API/Location/hostname translation_of: Web/API/Location/hostname ---

{{ApiRef("URL API")}}

{{domxref("Location")}}的 hostname 属性是包含了域名的一段 {{domxref("USVString")}}。

Syntax

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

Examples

// 在文档流中声明了一个元素: <a id="myAnchor" href="https://developer.mozilla.org/en-US/docs/Location.hostname">
var anchor = document.getElementById("myAnchor");
var result = anchor.hostname; // Returns:'developer.mozilla.org'

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', '#dom-location-hostname', 'hostname')}} {{Spec2('HTML WHATWG')}} Initial definition.

Browser compatibility

{{Compat("api.Location.hostname")}}