JavaScript 页面跳转方法:window.location.href 和 location.replace
使用 window.location.href 可以实现页面跳转,例如:
// 跳转到百度页面
window.location.href = 'https://www.baidu.com';
也可以使用 location.replace 方法实现页面跳转,例如:
// 跳转到谷歌页面
location.replace('https://www.google.com');
两种方式的区别在于,使用 window.location.href 会将当前页面加入浏览器历史记录,而 location.replace 则会替换当前页面,不会保留历史记录。
原文地址: https://www.cveoy.top/t/topic/nF4U 著作权归作者所有。请勿转载和采集!