<script language=vbs>
function rawurlencode(vstrin)
dim i,strreturn,strSpecial
strSpecial = " !""#$%&'()*+,/:;<=>?@[\]^`{|}~%"
strreturn = ""
for i = 1 to len(vstrin)
thischr = mid(vstrin,i,1)
if abs(asc(thischr)) < &hff then
if instr(strSpecial,thischr)>0 then
strreturn = strreturn & "%" & hex(asc(thischr))
else
strreturn = strreturn & thischr
end if
else
innercode = asc(thischr)
if innercode < 0 then
innercode = innercode + &h10000
end if
hight8 = (innercode and &hff00)\ &hff
low8 = innercode and &hff
strreturn = strreturn & "%" & hex(hight8) & "%" & hex(low8)
end if
next
rawurlencode=strreturn
end function
</script>
<script language="javascript">
alert(rawurlencode("http://localhost/test/测 试.txt"));
</script>
function rawurlencode(vstrin)
dim i,strreturn,strSpecial
strSpecial = " !""#$%&'()*+,/:;<=>?@[\]^`{|}~%"
strreturn = ""
for i = 1 to len(vstrin)
thischr = mid(vstrin,i,1)
if abs(asc(thischr)) < &hff then
if instr(strSpecial,thischr)>0 then
strreturn = strreturn & "%" & hex(asc(thischr))
else
strreturn = strreturn & thischr
end if
else
innercode = asc(thischr)
if innercode < 0 then
innercode = innercode + &h10000
end if
hight8 = (innercode and &hff00)\ &hff
low8 = innercode and &hff
strreturn = strreturn & "%" & hex(hight8) & "%" & hex(low8)
end if
next
rawurlencode=strreturn
end function
</script>
<script language="javascript">
alert(rawurlencode("http://localhost/test/测 试.txt"));
</script>
1、这个使用的vbs,如果使用javascript,如你前面所说的,是否只能利用GB转换库,手工转换?2、使用该方式进行转换,对整个url进行转换的话,会将url中/ :等也转换,是否,需要先手工分割取得url中的文件、目录名部分进行转换?
2。
<script language="javascript">
strUrl="http://localhost/test/测 试.txt"
intPos=strUrl.lastIndexOf("/")+1
alert(strUrl.substr(0,intPos)+rawurlencode(strUrl.substr(intPos)));
</script>