javascript - 自动将某人重定向到另一个网页的最佳方法是什么?

标签 javascript browser redirect

我从未学过 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/

相关文章:

javascript - 为什么我的这个 Jquery .post 的回调函数不工作?

javascript - 如何使用 jquery Ajax 和 json 数据将标签包装在 for 循环内?

javascript - Bootstrap 4 在右侧显示下拉子菜单

javascript - 更改 CSS 内部背景颜色

c# - 如何为Csharp Webbrowser提供下载文件的默认路径

java - 当我在后台运行 Selenium 脚本时,无法最大化 Selenium 中的浏览器

asp.net - 升级到 Visual Studio 2013 后为 "Failed to load resource: the server responded with a status of 401 (Unauthorized)"

javascript - 重定向而不是更改文本和发布

javascript - 使用 ui-router/Angular JS 设置重定向

django - 不理解 Django 管理员登录