使用jQuery或纯 JavaScript 如何将用户从一页转到另一页?


当前回答

尝试此 :

location.assign("http://www.google.com");

示例代码片断.

其他回答

我已经使用 JavaScript 的函数重定向() 。 它正在工作 。

<script type="text/javascript">
    $(function () {
        //It's similar to HTTP redirect
        window.location.replace("http://www.Technomark.in");

        //It's similar to clicking on a link
        window.location.href = "Http://www.Technomark.in";
    })
</script>

您可以在没有jQuery 的情况下这样做 :

window.location = "http://yourdomain.com";

如果你只想要jQuery, 你可以做它喜欢:

$jq(window).attr("location","http://yourdomain.com");

警告: 警告:答案只是作为一种可能的解决办法而已;显然最好的解决方案,因为它需要jQuery。 相反,它更喜欢纯 JavaScript 解决方案。

$(location).prop('href', 'http://stackoverflow.com')

您可以使用以下方法重定向页面:

  1. 通过在头部使用元标记 -<meta http-equiv="refresh" content="0;url=http://your-page-url.com" />注意:content="0;... 用于在您需要多少秒后重定向页面

  2. 使用 JavaScript :window.location.href = "http://your-page-url.com";

  3. 使用 jQuery 查询 :$(location).attr('href', 'http://yourPage.com/');

您可以在 jQuery 中像这样重定向 :

$(location).attr('href', 'http://yourPage.com/');