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