通过js实现页面的跳转
使用 window.location.href 跳转
通过修改 window.location.href 实现页面跳转,这是最常见的方法:
window.location.href = "https://example.com";
使用 window.location.replace 跳转
replace 方法会替换当前页面,不会在浏览器历史记录中留下痕迹:
window.location.replace("https://example.com");
使用 window.open 打开新窗口
在新标签页或窗口中打开页面,可通过参数控制行为:

window.open("https://example.com", "_blank");
使用 location.assign 跳转
assign 方法会加载新页面并保留历史记录:
window.location.assign("https://example.com");
使用 meta 标签自动跳转
通过 HTML 的 meta 标签实现自动跳转,适用于静态页面:

<meta http-equiv="refresh" content="5;url=https://example.com">
使用 history.pushState 修改 URL 但不跳转
仅修改 URL 而不刷新页面,适用于单页应用(SPA):
history.pushState({}, "", "new-page.html");
使用表单提交跳转
通过动态创建表单并提交实现跳转:
const form = document.createElement("form");
form.method = "GET";
form.action = "https://example.com";
document.body.appendChild(form);
form.submit();
使用 navigateTo(框架特定方法)
在 Vue、React 等框架中,通常使用路由方法跳转:
// Vue Router
this.$router.push("/target-page");
// React Router
import { useNavigate } from "react-router-dom";
const navigate = useNavigate();
navigate("/target-page");
注意事项
- 使用
window.open可能被浏览器拦截,需确保由用户触发(如点击事件)。 - 单页应用推荐使用框架路由方法,避免直接操作
window.location。 - 跳转前可添加条件判断或异步操作(如确认弹窗)。






