decodeURI没有完全正常工作

ixc*_*chi 10 javascript jquery

我正在尝试从链接中删除URI编码,但decodeURI似乎没有完全正常工作.

我的示例链接是这样的: /linkout?remoteUrl=http%253a%252f%252fsandbox.yoyogames.com%252fgames%252f171985-h-a-m-heroic-armies-marching

运行JavaScript脚本后,它看起来像这样:

http%3a%2f%2fsandbox.yoyogames.com%2fgames%2f171985-h-a-m-heroic-armies-marching
Run Code Online (Sandbox Code Playgroud)

如何摆脱URI中剩余的不正确的代码?

我的解码代码:

var href = $(this).attr('href');            // get the href
var href = decodeURI(href.substring(19));   // remove the outgoing part and remove the escaping
$(this).attr('href', 'http://'+href)        // change link on page
Run Code Online (Sandbox Code Playgroud)

Tob*_*ogh 33

网址看起来是两次编码,我也建议使用decodeURIComponent

decodeURIComponent(decodeURIComponent("http%253a%252f%252fsandbox.yoyogames.com%252fgames%252f171985-h-a-m-heroic-armies-marching"))
Run Code Online (Sandbox Code Playgroud)

结果:"http://sandbox.yoyogames.com/games/171985-ham-heroic-armies-marching"

但你应该检查为什么你提前两次编码网址