A hostname is a label assigned to a device (a host) on a network. It distinguishes one device from another on a specific network or over the internet. The hostname for a computer on a home network may be something like new laptop, Guest-Desktop, or FamilyPC.
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.
The location property of a window (i.e. window. location ) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window.
As specified by the definition:
So depending on your needs, you should use the one or the other. Most of the HTTP communication will go on default port 80, so you might omit it then. On the other hand, if you suspect that you need to take regard to non-standard port settings, you need to include that information in your source code as well.
Say we have this example:
example.org:1111
The hostname is the name - example.org
The host includes both the host name, and any port numbers associated - example.org:1111
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