我从未学过 JavaScript,但我认为这是一个非常简单的问题。只是想知道最近最推荐哪种方法。
最佳答案
// use this to avoid redirects when a user clicks "back" in their browser
window.location.replace('http://somewhereelse.com');
// use this to redirect, a back button call will trigger the redirection again
window.location.href = "http://somewhereelse.com";
// given for completeness, essentially an alias to window.location.href
window.location = "http://somewhereelse.com";
编辑:看起来发布更好答案的用户已经离开了,我在这里合并了他的答案。
关于javascript - 自动将某人重定向到另一个网页的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/200337/