url基本操作:
window.location.href => 'https://mp.csdn.net/mp_blog/creation/editor?example=cesTest#coments'
window.location.origin => 'https://mp.csdn.net'
window.location.protocol => 'https:'
window.location.host => 'mp.csdn.net'
window.location.hostname=>'mp.csdn.net'
window.location.port => ' '
window.location.pathname => '/mp_blog/creation/editor'
window.location.search => '?example=cesTest'
window.location.hash => '#coments'
window.location.assign('url')
window.location.replace('url')
window.location.reload()
window.location.toString()
window.location 和 window.open 的区别
window.location是window对象的属性,而window.open是window对象的方法
window.location是你对当前浏览器窗口的URL地址对象的参考!
window.open是用来打开一个新窗口的函数!
获取url的search参数值
例如href = 'https://mp.csdn.net/mp_blog/creation/editor?example=cesTest#coments'
let href = window.location.href
let urlParams = new URLSearchParams(href);
urlParams.get('example'); 返回的值是'cesTest'