--- title: 'Location: hostname' slug: Web/API/Location/hostname translation_of: Web/API/Location/hostname ---
{{ApiRef("URL API")}}
{{domxref("Location")}}的 hostname
属性是包含了域名的一段 {{domxref("USVString")}}。
string = object.hostname; object.hostname = string;
// 在文档流中声明了一个元素: <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'
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', '#dom-location-hostname', 'hostname')}} | {{Spec2('HTML WHATWG')}} | Initial definition. |
{{Compat("api.Location.hostname")}}