js实现页面跳转
使用 window.location.href
通过修改 window.location.href 属性实现页面跳转。这种方式会记录到浏览器的历史记录中,用户可以通过后退按钮返回上一页。
window.location.href = "https://example.com";
使用 window.location.replace
通过 window.location.replace 方法实现页面跳转。这种方式不会记录到浏览器的历史记录中,用户无法通过后退按钮返回上一页。
window.location.replace("https://example.com");
使用 window.open
通过 window.open 方法在新窗口或新标签页中打开页面。可以通过参数控制窗口的行为。

window.open("https://example.com", "_blank");
使用 meta 标签自动跳转
在 HTML 中使用 <meta> 标签实现自动跳转。这种方式适用于纯 HTML 场景。
<meta http-equiv="refresh" content="0; url=https://example.com">
使用表单提交跳转
通过动态创建表单并提交实现页面跳转。适用于需要传递表单数据的场景。

const form = document.createElement("form");
form.method = "GET";
form.action = "https://example.com";
document.body.appendChild(form);
form.submit();
使用 History API
通过 History API 的 pushState 或 replaceState 方法实现单页应用(SPA)的路由跳转,不会真正加载新页面。
history.pushState({}, "", "/new-page");
使用锚点跳转
通过修改 window.location.hash 实现页面内的锚点跳转。
window.location.hash = "#section1";






