Javascript window.location.host 和 window.location.hostname 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6549117/
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
Whats the difference between window.location.host and window.location.hostname
提问by Thomas Clayson
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?
那么有什么区别(如果有的话)以及应该在哪里使用?
回答by mplungjan
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
host....
: 主机名和端口号。[www.google.com]:80hostname
:主机名(不带端口号或方括号)。www.google.com