通过js实现页面的跳转页面跳转
使用 window.location.href 实现跳转
通过修改 window.location.href 可以直接跳转到目标 URL,浏览器会加载新页面并记录到历史记录中。
window.location.href = "https://example.com";
使用 window.location.replace 实现跳转
replace 方法会替换当前页面在历史记录中的条目,用户无法通过后退按钮返回原页面。
window.location.replace("https://example.com");
使用 window.open 打开新窗口或标签页
window.open 可以在新窗口或标签页中打开目标 URL,可通过参数控制窗口行为。

window.open("https://example.com", "_blank");
使用 meta 标签自动跳转
在 HTML 的 <head> 中添加 <meta> 标签,设置 http-equiv="refresh" 可实现定时跳转。
<meta http-equiv="refresh" content="5; url=https://example.com">
使用 history.pushState 或 replaceState 修改 URL
适用于单页应用(SPA),仅更新 URL 而不刷新页面,需配合路由库使用。

history.pushState({}, "", "/new-page");
使用表单提交跳转
动态创建表单并提交,适用于需要 POST 请求的跳转场景。
const form = document.createElement("form");
form.method = "POST";
form.action = "https://example.com";
document.body.appendChild(form);
form.submit();
使用 navigateTo 或框架路由方法
在 Vue、React 等框架中,可使用内置路由方法(如 router.push)实现跳转。
// Vue Router 示例
this.$router.push("/target-path");
注意事项
- 确保跳转前处理未保存的数据或用户确认。
- 跨域跳转可能受浏览器安全策略限制。
- 单页应用推荐使用框架路由,避免整页刷新。






