目录
二、window.open(window.open在safari浏览器失效)
跳转
一、window.location
1、使用window.location对象的assign()方法:可以通过将新的URL作为参数传递给assign()方法来实现页面跳转。
window.location.assign("跳转路径");
2、使用window.location对象的replace()方法:与assign()方法类似,但是replace()方法会替换当前页面的历史记录,而不会创建新的历史记录(不推荐,因为它会丢失当前页面的历史记录)。
window.location.replace("跳转路径");
3、使用window.location.href属性:可以将新的URL赋值给href属性来实现页面跳转。
window.location.href = "跳转路径";
二、window.open(window.open在safari浏览器失效)
window.open('跳转路径');
刷新
// 重新加载当前页面,不清空缓存
window.location.reload();
// 重新加载当前页面,清空缓存
window.location.reload(true);
history.go(0)
返回上一页
// window.history.back(返回历史页面的第几个页面);
window.history.back(-1);
页内跳转
// 定位到id是bar-sider
window.location.search = '#bar-sider';