javascript 窗口中主机和主机名的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13673389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between host and hostname in window
提问by Konrad Viltersten
Possible Duplicate:
Whats the difference between window.location.host and window.location.hostname
可能的重复:
window.location.host 和 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?
我期待在window
使用控制台变量,我注意到,有两个不同的领域,一个名为host
以及其他hostname
。在我检查了几个站点之后,两者的值似乎相同。它们之间有什么区别?哪个应该用于什么目的?
回答by Konrad Viltersten
As specified by the definition:
如定义所指定:
- hostnameis the host name (without the port number or square brackets)
- hostis the host name and port number
- hostname是主机名(不带端口号或方括号)
- host是主机名和端口号
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.
因此,根据您的需要,您应该使用其中一种。大多数 HTTP 通信将在默认端口 80 上进行,因此您可以忽略它。另一方面,如果您怀疑需要考虑非标准端口设置,则还需要在源代码中包含该信息。
回答by dsgriffin
Say we have this example:
假设我们有这个例子:
example.org:1111
The hostnameis the name - example.org
该主机的名称是-example.org
The hostincludes both the host name, and any port numbers associated - example.org:1111
该主机包括主机名,以及相关的任何端口号-example.org:1111