解码后改回 URL

Change URL back after decode

接受以下 URL 我使用解码删除 %3AF%2 等

http%3AF%2Fmo-d6fa3.ao.tzp.corp%3A3000%2Flogin%2Fcallback&client_id=x2.node";

为此我使用 var decodedUrl = decodeURIComponent(url)

我对此做了一些更改,我的问题是我应该如何 return 将其恢复为原始格式(如我发布的那样)。我尝试使用不起作用的编码...

只需调用encodeURIComponent()重新编码即可。

在此处查看工作示例:http://jsfiddle.net/q9dtcry4/

<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