如何使用jQuery或纯JavaScript将用户从一个页面重定向到另一个页面?
How can I redirect the user from one page to another using jQuery or pure JavaScript?
推荐答案一个不仅仅是重定向使用jQuery
jQuery不是必需的, window.location.replace(...) 将最好地模拟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.
如果您想模拟某人点击某个链接,请使用 location.href
If you want to simulate someone clicking on a link, use location.href
如果您想模拟HTTP重定向,请使用 location.replace
If you want to simulate an HTTP redirect, use location.replace
例如:
// similar behavior as an HTTP redirect window.location.replace("stackoverflow"); // similar behavior as clicking on a link window.location.href = "stackoverflow";更多推荐
如何重定向到其他网页?
发布评论