当前位置: 首页 > Web前端 > HTML

window.location常用属性

时间:2023-03-28 17:01:38 HTML

window.location公共属性window.location.href(获取当前页面地址或设置跳转到指定地址)https://www.iicoom.top/archived也可以使用window.location.href=https://万维网。iicom.top/archived跳转到此页面window.location.originhttps://www.iicoom.top/archived//window.location.origin获取以下信息'https://www.iicoom.top'window.location。pathname如果你的浏览器当前打开这个页面https://www.iicoom.top/posts/11window.location.pathname(设置或获取URL的路径部分(即文件地址))'/posts/11'window.location.protocolwindow.location.protocol(设置或获取URL的协议部分)'https:'window.location.host获取主机名window.location.host(设置或获取URL的主机部分)'www.iiicoom.top'window.location.portwindow.location.port(设置或获取与URL关联的端口号)window.location.searchwindow.location.search(设置或获取href属性后面的部分问号)?ie=UTF-8&wd=%E6%B5%8F%E8%A7%88%E5%99%A8%20window%20%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E9%A1%B5%E9%9D%A2%E8%B7%AF%E5%BE%84window.location.hash获取#window.location.hash后面的部分(设置或获取t井号“#”段后面的href属性)https://analytics.google.com/analytics/web/#/report-home/a138499935w199163389p193647340#/report-home/a138499935w199163389p193647340window.location.reload()刷新当前页面window.location.reload()解析vue页面的路径和查询//解析类似下面的结构//https://adult-app-h5.foundingaz.com/#/pages/answerDetail/answerDetail?issueId=56&answerId=1673exportfunctionparseUrl(url){letpath=''constquery={}letcache=url.split('#')复制代码[1].split('?')path=cache[0]//下面是查询cache[1]&&cache[1].split('&').forEach(pair=>{letkey_val=pair.split('=')query[key_val[0]]=key_val[1]})return{path,query}}//返回结果{paht:'/pages/answerDetail/answerDetail',query:{issueId:56,answerId:1673}}所以你可以直接使用router.push(parseUrl(url))来跳转。