location 对象表示当前页面的URL信息。例如,一个完整的URL:
https://www.baidu.com/s?tn=44004473_46_oem_dg&ie=utf-8&word=%E7%99%BE%E5%BA%A6
可以用location.href 获取。要获得URL各个部分的值,可以这么写:
location.protocol; // 'https'
location.host; // 'www.baidu.com'
location.port; // 端口号
location.pathname; // '/path/index.html'
location.search; // '?a=1&b=2'
location.hash; // 'TOP'
要加载一个新页面,可以调用location.assign() 。如果要重新加载当前页面,调用location.reload() 方法非常方便。
location.reload();
location.assign('https://blog.youkuaiyun.com/XQC_KKK?spm=1011.2415.3001.5343'); // 设置一个新的URL地址
996

被折叠的 条评论
为什么被折叠?



