由JQuery重定向到另一个页面

Dav*_*ecz 0 javascript jquery

我在我的网站上使用了jquery-1.8.0.min.js,我需要在某些情况下进行重定向.

我试过这个:

$('<div></div>').appendTo('body')
    .html('<div><h4>Some text....</h4></div>')
    .dialog({
        modal: true,
        title: 'Dialog title...',
        zIndex: 10000,
        autoOpen: true,
        width: 'auto',
        resizable: false,
        draggable: false,
        buttons: {
            Ok: function () {
                $(this).dialog("close");
                var loc = window.location;
                var currentURL = loc.protocol + '//' + loc.host + loc.pathname;

                var newUrl = loc.protocol + '//' + loc.host + 'Account/LogOn?ReturnUrl=' + urlencode(currentURL);
                $('<div style="dispaly:none;"></div>').appendTo('<body>').html('<a id="loginredirect" href="' + newUrl + ' "><br /></a>');
                $('#loginredirect').click();
            }
        },
        close: function (event, ui) {
            $(this).remove();
        }
    });
Run Code Online (Sandbox Code Playgroud)

但这不起作用:-(所以我试试这个:

$('<div></div>').appendTo('body')
    .html('<div><h4>Some text....</h4></div>')
    .dialog({
        modal: true,
        title: 'Dialog title...',
        zIndex: 10000,
        autoOpen: true,
        width: 'auto',
        resizable: false,
        draggable: false,
        buttons: {
            Ok: function () {
                $(this).dialog("close");
                var loc = window.location;
                var currentURL = loc.protocol + '//' + loc.host + loc.pathname;

                var newUrl = loc.protocol + '//' + loc.host + 'Account/LogOn?ReturnUrl=' + urlencode(currentURL);
                $(window.location).attr('href', newUrl);
            }
        },
        close: function (event, ui) {
            $(this).remove();
        }
    });
Run Code Online (Sandbox Code Playgroud)

但这也不起作用......

知道问题出在哪里?

谢谢

编辑1: 如果我正在尝试window.location.hrej = newUrl,FF ErrorConsole告诉我:NS_ERROR_MALFORMED_URI:组件返回失败代码:localhost/Content/scripts/jquery-1.8.0中的0x804b000a(NS_ERROR_MALFORMED_URI)[nsIDOMLocation.href]. min.js

和浏览器不要重定向到IE,FF和Chrome中的newUrl ...

Viv*_*k S 5

你不需要jquery,试试看,

window.location.href = new_url;
Run Code Online (Sandbox Code Playgroud)