【问题标题】:Window.Location Not Working In IE?Window.Location 在 IE 中不起作用?
【发布时间】:2012-02-07 04:53:55
【问题描述】:

我整个下午都在想办法解决这个问题,但现在放弃了,现在请聪明人帮忙:)

我有以下 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;
});

我已经尝试过使用完整网址和绝对网址的 window.location、window.location.href,但 IE 不喜欢它?有什么想法吗?

该函数只是从帖子中获取一个 Url,并且应该将用户重定向到该 Url。但就像我说的,在 Chrome 中可以正常工作,只是在 IE 中不行(尝试过 IE8 和 IE9)

【问题讨论】:

  • 你能在IE中调试并找到returnUrl包含的内容吗?
  • 不要在你的内部函数中return false
  • 查看此链接可能会有所帮助:stackoverflow.com/questions/4818868/…
  • returnUrl 正在返回 /mypage.aspx?p=12 或 mydomain.com/mypage.aspx?p=12#comment12?正如我所说,它在 Chrome 中工作,而不是“returnUrl”。我将尝试从内部函数中删除 return false 并查看是否对其进行排序
  • nope 删除 return false 没有任何区别,我实际上完全删除了它并尝试了 event.preventDefault() 但它仍然没有重定向 - 在调试器中检查了 url 并且没问题?

标签: javascript jquery internet-explorer window.location


【解决方案1】:

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

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

【讨论】:

  • 在成功的 ajax 帖子中调用 window.location.href 会产生同样的问题??
  • 用函数替换 window.location 对我不起作用。除了在 ajax 调用之后放置 window.location 之外的任何其他选择
猜你喜欢
  • 2010-11-13
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 2019-02-03
  • 2016-12-16
  • 2015-04-14
  • 2015-01-27
  • 2018-12-06
相关资源
最近更新 更多