简体   繁体   English

将用户重定向到主页而不重新加载页面

[英]Redirect user to home page without reloading page

After clicking okay on my window.prompt a new tab opens using the code below.在我的window.prompt上单击确定后,使用下面的代码打开一个新选项卡。 I want the user to go to the home page without opening a new tab.我希望用户在不打开新标签的情况下将 go 转到主页。

if (window.confirm("Do you really want to leave?")) {
    window.open("./Tutorial2", "Thanks for Visiting!");
} 

The window.open() (method) , will open in a new window. window.open() (方法)将在新的 window 中打开。 You can use window.location (object) along with .href = "urladdress" to redirect your browser to a new url address without opening a new tab.您可以使用window.location (object).href = "urladdress"将浏览器重定向到新的 url 地址,而无需打开新选项卡。

See the following article on MDN: Window.location for more info.有关更多信息,请参阅MDN 上的以下文章:Window.location

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM