window.location 方法及作用

字段:http://localhost:9094/#/source/source-catalog
1、设置或获取整个 URL 为字符串

window.location.href
http://localhost:9094/#/source/source-catalog

2、设置或获取 URL 的协议部分

window.location.protocol
http:

3、设置或获取 URL 的主机部分

window.location.host
localhost:9094

4、设置或获取与 URL 关联的端口号码

window.location.port
9094

5、设置或获取与 URL 的路径部分(就是文件地址)

window.location.pathname
直接设置,端口后会直接加上下载路径
/rcservcie/doc?5c3a975b-3773-467c-a52a-5a490f38cf44
http://localhost:9094/rcservcie/doc%3F5c3a975b-3773-467c-a52a-5a490f38cf44#/source/source-catalog

6、设置或获取 href 属性中跟在问号后面的部分

window.location.search
resource_id=bee59caad39a490e9411c5af1dfcab40

7、设置或获取 href 属性中在井号“#”后面的分段

window.location.hash
#/source/source-catalog

相关文章