HTML / JS 页面跳转的方式
HTML
// 5秒后跳转
<meta http-equiv="refresh" content="5; url=https://example.com">
// 直接跳转
<meta http-equiv="refresh" content="0; url=https://example.com">
3. JavaScript跳转
通过前端脚本控制跳转,灵活性高:
window.location.href(最常用):
window.location.href = "https://example.com";
window.location.replace()(不保留历史记录):
window.location.replace("https://example.com");
window.location.assign()(类似href):
window.location.assign("https://example.com");
window.open()(新窗口/标签页打开):
window.open("https://example.com", "_blank");
history.pushState() / history.replaceState()(单页应用SPA路由跳转):
history.pushState({}, "", "/new-path"); // 修改URL但不刷新页面