通过js实现页面的跳转
使用 window.location.href 进行跳转
设置 window.location.href 为目标 URL,浏览器会立即加载新页面:
window.location.href = "https://example.com";
使用 window.location.replace 替换当前页面
replace 方法不会在浏览器历史记录中留下当前页面的记录:
window.location.replace("https://example.com");
使用 window.open 打开新窗口或标签页
在新窗口或标签页中打开目标 URL,可通过参数控制打开方式:

window.open("https://example.com", "_blank");
使用 location.assign 导航到新页面
assign 方法会在浏览器历史记录中保留当前页面:
window.location.assign("https://example.com");
使用 meta 标签自动跳转
通过设置 <meta> 标签的 http-equiv 属性实现自动跳转:

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 = "POST";
form.action = "https://example.com";
document.body.appendChild(form);
form.submit();
使用 history.pushState 修改 URL 而不刷新
适用于单页应用(SPA),仅修改 URL 而不实际跳转:
window.history.pushState({}, "", "https://example.com/new-path");
使用锚点跳转
通过修改 hash 实现页面内跳转:
window.location.hash = "#section-id";






