js实现页面的跳转页面
JavaScript 页面跳转方法
window.location.href
设置 window.location.href 为目标 URL 实现跳转:
window.location.href = "https://example.com";
window.location.replace
替换当前页面,不保留历史记录:

window.location.replace("https://example.com");
window.open
在新窗口或标签页中打开页面:
window.open("https://example.com", "_blank");
meta 标签跳转
通过动态创建 meta 标签实现跳转:

const meta = document.createElement("meta");
meta.httpEquiv = "refresh";
meta.content = "0;url=https://example.com";
document.head.appendChild(meta);
表单提交跳转
使用 JavaScript 提交表单实现跳转:
const form = document.createElement("form");
form.method = "GET";
form.action = "https://example.com";
document.body.appendChild(form);
form.submit();
注意事项
- 使用
replace()会覆盖当前页面历史记录,用户无法通过返回按钮回到原页面 window.open可能被浏览器拦截,需用户主动允许弹窗- 部分方法需考虑跨域限制






