url处理方法

2019-08-06  本文已影响0人  牛妈代代

使用window.location方法获取常用属性如下

window.location.href 返回当前页面的 href (https://www.jianshu.com/)
window.location.hostname 返回 web 主机的域名(www.jianshu.com)
window.location.pathname 返回当前页面的路径或文件名(带/)
window.location.port 返回但口号(8090)
window.location.protocol 返回使用的 web 协议(http: 或 https:)
window.location.search 返回请求的参数(?及后面内容)
window.location.hash  获取 href 属性中在井号“#”后面的分段。
window.location.assign  加载新文档

设置url直接写相对于属性等一设置的url即可,多用于url传参;

上一篇 下一篇

猜你喜欢

热点阅读