Copy codeThe Code is as follows:
<Script type = "text/vbscript">
Function str2asc (strstr)
Str2asc = hex (asc (strstr ))
End Function
Function asc2str (ascasc)
Asc2str = chr (ascasc)
End Function
</Script>
Convert vbscript functions to javascript for use in non-ie browsers
Copy codeThe Code is as follows:
Function str2asc (strstr ){
Return ("0" + strstr. charCodeAt (0). toString (16). slice (-2 );
}
Function asc2str (ascasc ){
Return String. fromCharCode (ascasc );
}
Copy codeThe Code is as follows:
<Script type = "text/javascript">
/* UrlEncode and UrlDecode functions at the beginning */
Function UrlEncode (str ){
Var ret = "";
Var strSpecial = "! \ "# $ % & '() * +,/:; <=>? [] ^ '{| }~ % ";
Var tt = "";
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;
}
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>