They both seem to give me the same thing (the domain name currently executing the script).
So what's the difference (if any) and where should each be used?
The window.location.hostname property returns the name of the internet host (of the current page).
The location. host property returns the host (IP adress or domain) and port of a URL. The location. host property can also be set, to navigate to the same URL with a new host and port.
window. location is read/write on all compliant browsers. document. location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).
MDN Web Docs - window.location
host....
: the host name and port number. [www.google.com]:80hostname
: the host name (without the port number or square brackets). www.google.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With