Location hostnameProperty
Location Object
Definition and Usage
The hostname property is a readable and writable string that can set or return the hostname of the current URL.
Syntax
location.hostname
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the hostname property
Examples
Examples
Return the hostname of the current URL:
<script>
document.write(location.hostname);
</script>
document.write(location.hostname);
</script>
The output of the above example is:
Try it yourself »
Location Object Other Extensions