AngularJS Firefox encoded URL

AngularJS Firefox encoded URL

本文关键字:URL encoded Firefox AngularJS      更新时间:2023-09-26

我在 Angular 上使用 Firefox 时遇到了一个奇怪的问题,我不知道如何修复它或研究什么才能提出解决方案。火狐浏览器中的所有网址如下:

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

Chrome 中的相同网址如下所示:

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

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

提前谢谢。

您可以使用

decodeURIComponent()来解码网址。

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

请注意,结果可能不是有效的网址。

有关更多详细信息:

解码URI

和解码URI有什么区别?

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