“`”

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

<pre><code> "“`

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.