【问题标题】:AngularJS Firefox encoded URLAngularJS Firefox 编码的 URL
【发布时间】:2014-12-10 16:08:58
【问题描述】:

我在 Angular 上使用 Firefox 时遇到了一个奇怪的问题,我不知道如何修复它或研究什么才能找到解决方案 Firefox 中的所有 URL 如下:

http://www.domain.com/#somehash|%2FMerchant%2Fmerchant.com

Chrome 中相同的 URL 如下所示:

http://www.domain.com/#somehash|/Merchant/merchant.com

这在 Firefox 中被证明是有问题的,因为我们正在对 URL 进行一些条件检查,这导致 Firefox 的一些 if 条件由于编码而失败。

提前致谢。

【问题讨论】:

    标签: javascript angularjs firefox urlencode


    【解决方案1】:

    您可以使用decodeURIComponent() 来解码网址。

    decodeURIComponent('http://www.domain.com/#somehash|%2FMerchant%2Fmerchant.com')
    => "http://www.domain.com/#somehash|/Merchant/merchant.com"
    

    请记住,结果可能不是有效的 URL。

    更多详情:

    What is the difference between decodeURIComponent and decodeURI?

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/decodeURIComponent

    【讨论】:

    • 这是可能的,但是我想知道为什么不同浏览器的行为不一致
    • 您是如何获得网址的? document.URL 应该跨浏览器保持一致
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    相关资源
    最近更新 更多