2015-08-24 74 views
0

香港專業教育學院下面的網址,我用解碼刪除%3AF%2等更改URL後面

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

爲我用var decodedUrl = decodeURIComponent(url)

我做了一些改變這一點,我的問題是我應該如何將它恢復爲原始格式(如我發佈的)。我嘗試使用編碼,這不工作...

+0

你嘗試encodeURIComponent方法()? – HaukurHaf

+1

你的意思是'編碼不起作用'? encodeURIComponent的確如此... – cviejo

回答

1
<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