本文介绍了如何重定向到其他网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用jQuery或纯JavaScript将用户从一个页面重定向到另一个页面?
How can I redirect the user from one page to another using jQuery or pure JavaScript?
推荐答案
一个不仅仅是重定向使用jQuery
jQuery不是必需的,将最好地模拟HTTP重定向。
One does not simply redirect using jQuery
jQuery is not necessary, and window.location.replace(...)
will best simulate an HTTP redirect.
window.location.replace(...)
优于使用窗口。 location.href
,因为 replace()
不会将原始页面保留在会话历史记录中,这意味着用户不会陷入永不停滞的状态 - 后退按钮惨败。
window.location.replace(...)
is better than using window.location.href
, because replace()
does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco.
如果您想模拟HTTP重定向,请使用 location.replace
If you want to simulate an HTTP redirect, use location.replace
例如:
// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");
// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
这篇关于如何重定向到其他网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!