【问题标题】:location.replace and base tag : strange behavior in IElocation.replace 和 base 标签:IE 中的奇怪行为
【发布时间】:2015-05-22 09:34:11
【问题描述】:

我的页面中有这个基本标签:

<base href="http://localhost:8080/application/module/jsp/Vues/">

当我在 Chrome 中测试 location.replace 时,它的行为符合预期,使用基本 url:

location.replace(test)
=> http://localhost:8080/application/module/jsp/Vues/test

但 IE 似乎忽略了基本 URL,而是使用当前位置:

location.replace(test)
=> http://localhost:8080/application/module/jsp/test

任何想法为什么 IE 忽略基本标记?如何让两个浏览器有相同的行为?

【问题讨论】:

    标签: javascript html google-chrome internet-explorer url


    【解决方案1】:

    今天遇到了同样的问题。经过长时间的研究,我放弃并设置了绝对 URL。

    var baseUrl = $('base').attr('href');
    location.replace(baseUrl + relativeUrl);
    

    location.replace(location.origin + baseUrl + relativeUrl);
    

    如果你的基本元素中有相对路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-17
      • 2020-10-26
      • 1970-01-01
      • 2013-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多