企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[https://www.runoob.com/jsref/obj-location.html](https://www.runoob.com/jsref/obj-location.html) [https://developer.mozilla.org/zh-CN/docs/Web/API/Location](https://developer.mozilla.org/zh-CN/docs/Web/API/Location) ``` console.log(window.location.href)//http://www.aoweiya.com/index/ProductOage/index.html?cate=74&p=2#dash console.log(window.location.pathname)//index/ProductOage/index.html console.log(window.location.hash)//#dash console.log(window.location.host)//www.aoweiya.com console.log(window.location.host)//www.aoweiya.com console.log(window.location.hostname)//www.aoweiya.com console.log(window.location.port)//"" console.log(window.location.protocol)//http: console.log(window.location.search)//?cate=74&p=2 ``` ## Location 对象属性 | 属性 | 描述 | | :-- | :-- | | [hash](https://www.runoob.com/jsref/prop-loc-hash.html) | 返回一个URL的锚部分 | | [host](https://www.runoob.com/jsref/prop-loc-host.html) | 返回一个URL的主机名和端口 | | [hostname](https://www.runoob.com/jsref/prop-loc-hostname.html) | 返回URL的主机名 | | [href](https://www.runoob.com/jsref/prop-loc-href.html) | 返回完整的URL | | [pathname](https://www.runoob.com/jsref/prop-loc-pathname.html) | 返回的URL路径名。 | | [port](https://www.runoob.com/jsref/prop-loc-port.html) | 返回一个URL服务器使用的端口号 | | [protocol](https://www.runoob.com/jsref/prop-loc-protocol.html) | 返回一个URL协议 | | [search](https://www.runoob.com/jsref/prop-loc-search.html) | 返回一个URL的查询部分 | ## Location 对象方法 | 方法 | 说明 | | :-- | :-- | | [assign()](https://www.runoob.com/jsref/met-loc-assign.html) | 载入一个新的文档 | | [reload()](https://www.runoob.com/jsref/met-loc-reload.html) | 重新载入当前文档 | | [replace()](https://www.runoob.com/jsref/met-loc-replace.html) | 用新的文档替换当前文档 |