Javascript 解码后将URL更改回原处

Javascript 解码后将URL更改回原处,javascript,node.js,url,urldecode,Javascript,Node.js,Url,Urldecode,我输入以下URL,并使用decode删除%3AF%2等 http%3AF%2Fmo-d6fa3.ao.tzp.corp%3A3000%2Flogin%2Fcallback&client_id=x2.node"; 为此,我使用了var decodedUrl=decodeURIComponent(url) 我对此做了一些更改,我的问题是如何将其返回到原始格式(如我发布的)。我尝试使用不起作用的encode…只需调用encodeURIComponent()再次编码即可 请参阅此处的工作示例:

我输入以下URL,并使用decode删除%3AF%2等

http%3AF%2Fmo-d6fa3.ao.tzp.corp%3A3000%2Flogin%2Fcallback&client_id=x2.node";
为此,我使用了
var decodedUrl=decodeURIComponent(url)


我对此做了一些更改,我的问题是如何将其返回到原始格式(如我发布的)。我尝试使用不起作用的encode…

只需调用
encodeURIComponent()
再次编码即可


请参阅此处的工作示例:

您是否尝试了encodeURIComponent()?您所说的“encode不工作”是什么意思?编码器组件正是这样做的。。。
<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var uri = "http:F/mo-d6fa3.ao.tzp.corp:3000/login/callback&client_id=x2.node";
    var uri_enc = encodeURIComponent(uri);
    var uri_dec = decodeURIComponent(uri_enc);
    var res = "Encoded URI: " + uri_enc + "<br>" + "Decoded URI: " + uri_dec;
    document.getElementById("demo").innerHTML = res;
}
</script>
Encoded URI: http%3AF%2Fmo-d6fa3.ao.tzp.corp%3A3000%2Flogin%2Fcallback%26client_id%3Dx2.node
Decoded URI: http:F/mo-d6fa3.ao.tzp.corp:3000/login/callback&client_id=x2.node