js实现自动跳转
使用 window.location 实现跳转
通过修改 window.location.href 实现页面跳转,适用于大多数场景:
window.location.href = "https://example.com";
若需延迟跳转(如3秒后),可结合 setTimeout:

setTimeout(() => {
window.location.href = "https://example.com";
}, 3000);
使用 window.location.replace 实现无历史记录跳转
replace 方法会替换当前页面历史记录,用户无法通过浏览器后退按钮返回原页面:
window.location.replace("https://example.com");
使用 meta 标签实现HTML自动跳转
在HTML的 <head> 中添加以下代码,设定跳转时间和目标URL:

<meta http-equiv="refresh" content="5;url=https://example.com">
content 中的 5 表示延迟5秒跳转。
使用 window.open 在新窗口/标签页跳转
通过 window.open 在新标签页打开链接,需注意浏览器可能拦截弹出窗口:
window.open("https://example.com", "_blank");
注意事项
- 跳转前可添加用户提示(如“页面即将跳转”)。
- 部分浏览器可能限制频繁跳转行为,需测试兼容性。
- 确保目标URL有效性,避免死循环或404错误。






