<script language= "JavaScript" >
UrlEncode function
function UrlEncode (str) {
var ret= "";
var strspecial= "!\" #$%& ' () *+,/:;<=>? []^`{|} ~%";
for (Var i=0;i<str.length;i++) {
var chr = Str.charat (i);
var c=str2asc (CHR);
tt + = chr+ ":" +c+ "n";
if (parseint ("0x" +c) > 0x7f) {
ret+= "%" +c.slice (0,2) + "%" +c.slice (-2);
}else{
if (chr== "")
ret+= "+";
else if (Strspecial.indexof (CHR)!=-1)
ret+= "%" +c.tostring (16);
Else
RET+=CHR;
}
}
return ret;
}
UrlDecode function:
function UrlDecode (str) {
var ret= "";
for (Var i=0;i<str.length;i++) {
var chr = Str.charat (i);
if (Chr = = "+") {
ret+= "";
}else if (chr== "%") {
var asc = str.substring (i+1,i+3);
if (parseint ("0x" +asc) >0x7f) {
Ret+=asc2str (parseint ("0x" +asc+str.substring (i+4,i+6)));
i+=5;
}else{
Ret+=asc2str (parseint ("0x" +asc));
i+=2;
}
}else{
ret+= CHR;
}
}
return ret;
}
Alert (UrlDecode ("%c2%d2%c2%eb"));
</script>
UrlEncode and UrlDecode function codes based on JS implementation