是什么区别window.location.host和window.location.hostname [英] Whats the difference between window.location.host and window.location.hostname

查看:719
本文介绍了是什么区别window.location.host和window.location.hostname的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们似乎都给了我相同的东西(当前正在执行脚本的域名)。

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?

推荐答案

MDN Web Docs - window.location

主机.... :主机名和端口号。 [www.google.com]:80

主机名:主机名(不带端口号或方括号) 。 www.google.com

host....: the host name and port number. [www.google.com]:80
hostname: the host name (without the port number or square brackets). www.google.com

这篇关于是什么区别window.location.host和window.location.hostname的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆