當你在使用JavaScript來做一些GET指令時你應該經常會發現一個問題就是JavaScript他會要求你把網址編碼吧,遇到這種需要編碼網址才能使用的函式你可以使用encodeURIComponent來幫網址進行編碼

2009-07-22_144915

. encodeURIComponent語法格式:

var 儲存用變數=encodeURIComponent("被加密網址")

.

.

範例:

在網址列貼上以下語法

javascript:alert(encodeURIComponent(location.href));

2009-07-22_145001

另外你可以使用decodeURIComponwent來把被encodeURIComponent編碼過的網址回復原狀

2009-07-22_145730

語法格式跟encodeURIComponent一樣都是:

var 儲存用變數=encodeURIComponent("被加密網址") 

2009-07-22_145924