Difference between host and hostname in window [duplicate]

Possible Duplicate:
Whats the difference between window.location.host and window.location.hostname

I'm looking at the window variable using the console and I notice that there are two different fields, one named host and the other hostname. After I've checked a few sites, there seems to be the same value in both. What is the difference between them? Which should be used for what purpose?

2

2 Answers

As specified by the definition:

  • hostname is the host name (without the port number or square brackets)
  • host is the host name and port number

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.

3

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

You Might Also Like