通过js实现页面的跳转页面
使用 window.location.href
通过修改 window.location.href 属性实现页面跳转,这是最常见的方法。
window.location.href = 'https://example.com';
使用 window.location.replace
replace 方法会替换当前页面在历史记录中的条目,用户无法通过返回按钮回到原页面。
window.location.replace('https://example.com');
使用 window.location.assign
assign 方法加载新页面,保留历史记录,用户可通过返回按钮回到原页面。

window.location.assign('https://example.com');
使用 window.open
在新窗口或标签页中打开页面,可通过参数控制打开方式。
window.open('https://example.com', '_blank');
使用 meta 标签自动跳转
通过动态创建 <meta> 标签实现自动跳转,常用于 HTML 文件。

const meta = document.createElement('meta');
meta.httpEquiv = 'refresh';
meta.content = '0;url=https://example.com';
document.head.appendChild(meta);
使用表单提交跳转
动态创建表单并提交,适合需要传递参数的场景。
const form = document.createElement('form');
form.method = 'POST';
form.action = 'https://example.com';
document.body.appendChild(form);
form.submit();
使用 history.pushState 或 replaceState
适用于单页应用(SPA),仅更新 URL 而不刷新页面。
history.pushState({}, '', '/new-page');
注意事项
- 使用
window.location相关方法时,确保目标 URL 合法且安全。 window.open可能被浏览器拦截,需用户主动触发(如点击事件)。- 表单提交跳转适合需要传递复杂参数的场景,但会引发页面刷新。






