使用JavaScript重定向到其他网页的一些方法:

  • location.href

  • location.replace()

  • location.assign()

语法:

window.location.href="URL" //或者
location.replace("URL") //或者
location.assign("URL")

参数:

接受单个参数的URL,这是必需的。用于指定新网页的引用。

返回值:

无返回值。

注意:

所有方法的输出都相同,但location.replace()方法从文档历史记录中删除当前文档的URL。因此,如果希望选项导航回原始文档,最好使用location.assign()方法。