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="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 实现单页应用(SPA)内的路由跳转:

history.pushState({}, '', '/new-page');
使用锚点跳转
跳转到当前页面的指定锚点:
window.location.hash = 'section-id';
使用 JavaScript 事件触发
通过事件触发跳转,例如点击按钮:
document.getElementById('button').addEventListener('click', () => {
window.location.href = 'https://example.com';
});
使用 setTimeout 延迟跳转
延迟一定时间后跳转:
setTimeout(() => {
window.location.href = 'https://example.com';
}, 3000);






