js怎么实现网页跳转页面跳转
使用 window.location.href
设置 window.location.href 为目标 URL,浏览器会立即跳转至新页面:
window.location.href = "https://example.com";
使用 window.location.replace
window.location.replace 会替换当前页面,不会在历史记录中留下痕迹:

window.location.replace("https://example.com");
使用 window.open
在新窗口或标签页中打开目标 URL,可通过参数控制行为:
window.open("https://example.com", "_blank");
使用 meta 标签自动跳转
在 HTML 的 <head> 中添加 meta 标签实现自动跳转,适合无交互场景:

<meta http-equiv="refresh" content="5; url=https://example.com">
使用表单提交跳转
通过动态创建表单并提交实现跳转,适合需要传递数据的场景:
const form = document.createElement("form");
form.method = "GET";
form.action = "https://example.com";
document.body.appendChild(form);
form.submit();
使用导航 API(现代浏览器)
现代浏览器支持 Navigation API,提供更精细的控制:
navigation.navigate("https://example.com");
注意事项
- 使用
window.location.href会记录历史,replace则不会。 window.open可能被浏览器拦截,需用户触发。- 表单提交适用于需要传递参数的跳转。
- 现代 API 如 Navigation 需检查兼容性。






