实现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="5;url=https://example.com">
使用表单提交跳转
通过 JavaScript 提交表单实现跳转:
document.getElementById("myForm").submit();
使用锚点链接跳转
通过修改 location.hash 实现页面内跳转:

window.location.hash = "#section2";
使用 history.pushState
在不刷新页面的情况下修改 URL:
history.pushState({}, "", "newpage.html");
使用框架跳转
在 iframe 中跳转:
document.getElementById("myFrame").src = "newpage.html";
使用导航按钮跳转
模拟浏览器前进后退按钮:
history.back(); // 后退
history.forward(); // 前进






