javascript Window.Location 在 IE 中不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8809025/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 04:39:08  来源:igfitidea点击:

Window.Location Not Working In IE?

javascriptjqueryinternet-explorerwindow.location

提问by leen3o

I have been trying to figure this out all afternoon, but have given up and now turning to you clever people to help :)

我整个下午都在试图解决这个问题,但已经放弃,现在求助于聪明的人来帮助:)

I have the following Jquery/Javascript function, which is working fine in Chrome - BUT in IE nothing happens?

我有以下 Jquery/Javascript 函数,它在 Chrome 中运行良好 - 但在 IE 中没有任何反应?

    $(".btnsubmitpost").click(function () {
    var topicid = $(this).attr('rel');
    var sbody = tinyMCE.get('txtPost').getContent();
    $('.topicpostlistnewpost').remove();
    $('.postsuccess').show();
    $.post("/myurl/" + topicid + ".aspx",
           { "postcontent": sbody },
            function (data) {
                var returnUrl = $("value", data).text();
                window.location.href = returnUrl;
                return false;
            });
    return false;
});

I have tried window.location, window.location.href both with full urls and absolute Urls but IE just doesn't like it? Any ideas?

我试过 window.location、window.location.href 都带有完整网址和绝对网址,但 IE 就是不喜欢它?有任何想法吗?

The function just gets a Url back from a post, and is supposed to redirect the user to the Url. But like I say, works in Chrome fine just not in IE (Tried IE8 and IE9)

该函数只是从帖子中获取一个 Url,并应该将用户重定向到该 Url。但就像我说的,在 Chrome 中工作得很好,但在 IE 中却没有(尝试过 IE8 和 IE9)

采纳答案by leen3o

Just for anyone having the same issue, the problem was because the window.location was inside the Ajax post method.

对于有同样问题的人来说,问题是因为 window.location 在 Ajax post 方法中。

Just replace the window.location with a function() that then calls the window.location or do it after the Ajax call completely.

只需将 window.location 替换为 function(),然后调用 window.location 或在 Ajax 调用完全之后执行。