在 JavaScript 中,可以使用 window.location.href 来实现页面跳转。具体的用法如下:

window.location.href = 'https://www.example.com';

上述代码将会将当前页面跳转到 https://www.example.com。你可以将目标 URL 替换为你想要跳转的页面的 URL。

另外,你也可以使用 window.location.replace() 方法来实现页面跳转。与 window.location.href 相比,window.location.replace() 会替换当前页面的历史记录,使用户无法返回到之前的页面。

window.location.replace('https://www.example.com');

无论是使用 window.location.href 还是 window.location.replace(),都会导致浏览器加载新的页面并跳转到指定的 URL。

JavaScript 页面跳转:window.location.href 和 window.location.replace() 方法详解

原文地址: https://www.cveoy.top/t/topic/pihn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录