Standort: hostname-Eigenschaft
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Die hostname
-Eigenschaft des Location
-Interfaces ist ein String, der entweder den Domainnamen oder die IP-Adresse der Standort-URL enthält. Wenn die URL keinen Hostnamen hat, enthält diese Eigenschaft einen leeren String, ""
. IPv4- und IPv6-Adressen werden normalisiert, z. B. durch das Entfernen führender Nullen, und Domainnamen werden in IDN umgewandelt.
Weitere Informationen finden Sie unter URL.hostname
.
Wert
Ein String.
Beispiele
console.log(window.location.hostname);
// developer.mozilla.org
const anchor = document.createElement("a");
anchor.href = "https://developer.mozilla.org:4097/";
console.log(anchor.hostname === "developer.mozilla.org");
// The port number is not included in hostname
Spezifikationen
Specification |
---|
HTML # dom-location-hostname-dev |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
hostname |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- User must explicitly enable this feature.