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


当前回答

我已经使用 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>

其他回答

根据我的工作经验 JavaScript 更适合重新定位

它取决于您要如何更改地址。 如果您想要在用户历史中登录您的网站, 请使用window.location.href='ur website';否则在不记录历史的情况下使用window.location.replace("your website");.

使用 jQuery 函数 :

$.extend({
  redirectPost: function(location, args) {
    var form = '';
    $.each(args, function(key, value) {
      form += '<input type="hidden" name="' + key + '" value="' + value + '">';
    });
    $('<form action="' + location + '" method="POST">' + form + '</form>').appendTo($(document.body)).submit();
  }
});

在你的代码中,你使用它这样:

$.redirectPost("addPhotos.php", {pimreference:  $("#pimreference").val(), tag: $("#tag").val()});

每个浏览器都使用此功能 :

window.location.href = 'your_url';

我只是不得不更新这种荒谬的 另一种新的jQuery方法:

var url = 'http://www.fiftywaystoleaveyourlocation.com';
$(location).prop('href', url);

与 jQuery 合作 :

$(window).attr("location", "http://google.fr");