utf-8在responseBody中得编码方式
239|187| 191|233| xxx|xxx| 233|xxx|xxx|233| xxx|xxx| ...
应用示例代码:
<html>
<body>
<div id="mt"></div>
<script language="VBScript" type="text/VBScript">
Function rsCode(vIn,num)
rsCode=AscB(MidB(vIn,num,1))
End Function
Function rsLength(vIn)
rsLength=LenB(vIn)
End Function
Function rsChar(num)
rsChar=Chr(num)
End Function
</script>
<script language="JavaScript" type="text/JavaScript">
//虽然也是参考了很多别人的资料才写出来的,但也花了不少功夫,转载请注明出处
//you can use if freely, but you should keep the words below!
//Copyright shouhaimu(QQ:30836570)
self.onerror=null;
var Http = new ActiveXObject("Microsoft.XMLHTTP");
Http.open("GET","2.htm",false);
//我存了俩个文件,1.htm为utf-8格式,2.htm为gb2312格式,现在用此程序均成功加载并正常显示。
Http.send();
var x=Http.responseBody;
var utf_8=(rsCode(x,1)==239&&rsCode(x,2)==187&&rsCode(x,3)==191)
if(utf_8)mt.innerHTML=Http.responseText;
Http=null;
if(!utf_8)
{
var y=rsLength(x),z,i=1,t="";
while(i<=y)
{
z=rsCode(x,i++);
if(z<128)
{
t+=z;
}
else
{
t+=rsChar(z*256+rsCode(x,i++));
}
}
mt.innerHTML=t;
}
</script>
</body>
</html>
posted on 2006-08-02 15:38
汪杰 阅读(269)
评论(0) 编辑 收藏 引用 所属分类:
javascript