js实现页面的跳转
使用 window.location.href
通过修改 window.location.href 实现页面跳转,这是最常见的方式:
window.location.href = 'https://example.com';
使用 window.location.replace
与 href 类似,但会替换当前页面历史记录,无法通过浏览器后退按钮返回:
window.location.replace('https://example.com');
使用 window.open
在新窗口或标签页中打开页面,可通过参数控制行为:

window.open('https://example.com', '_blank');
使用 location.assign
与 href 效果相同,但语义更明确:
window.location.assign('https://example.com');
使用 meta 标签自动跳转
通过 HTML 的 <meta> 标签实现自动跳转,适合纯前端场景:

<meta http-equiv="refresh" content="0;url=https://example.com">
使用表单提交跳转
通过 JavaScript 动态提交表单实现跳转,适合需要传递参数的场景:
const form = document.createElement('form');
form.method = 'POST';
form.action = 'https://example.com';
document.body.appendChild(form);
form.submit();
使用 History API
适用于单页应用(SPA),不刷新页面修改 URL:
history.pushState({}, '', '/new-page');
注意事项
- 跳转外部域名时需注意跨域限制
- 某些浏览器可能会拦截弹出窗口
- 单页应用跳转需配合路由库使用
- 移动端需考虑用户体验和性能影响






