浏览器宿主环境中,有一个location对象,同时这个对象也是window对象和document对象的属性。location对象中提供了与当前窗口加载的文档有关的的信息,即URL信息。如 https://www.baidu.com/api/sousu?search=baidu&id=123#2location.href: 完整URLlocation.protocol: 返回协议(https:)location.host: 返回服务器名称和端口号(www.baidu.com)location.hostname: 返回服务器名称(www.baidu.com)location.port:返回服务器端口号(http默认80,https默认443)location.pathname:返回URL中的目录和文件名(api/sousu)location.search:返回查询字符串(?search=baidu&id=123#2)location.hash:返回hash值(#2)



