如何重定向到其他网页?

编程入门 行业动态 更新时间:2024-10-22 09:53:26
本文介绍了如何重定向到其他网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何使用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";

更多推荐

如何重定向到其他网页?

本文发布于:2023-10-12 16:58:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485319.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   网页

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!