Loading, please wait...

Tuesday, October 7, 2008

两种方法转码本地文本文件

web这方面编码是一个相当头疼的问题,这两种方法进行编码转换(ie only)

方法一:用函数进行编码转换
<SCRIPT language="VBScript" type="text/VBScript">
Function bytes2BSTR(vIn)
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
</script>

<script language="javascript">
function GetData()
{
loadcontent.innerText=getDatal("index.php")
setTimeout("GetData()",1000);
}

function getDatal(url){  
       var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.4.0");
       xmlhttp.open("post",url,false);   
       xmlhttp.send();              
       return bytes2BSTR(xmlhttp.responsebody);       
       xmlhttp=nothing
}  
</script>
<BODY onload="javascript:GetData();">
<span id="loadcontent">数据载入中……</span>
</BODY>

方法二:IE下用ADODB.RecordSet解决
<body text=00ff00 bgcolor=black></body><script>
xml=new ActiveXObject("Microsoft.XmlHttp");
rs=new ActiveXObject("ADODB.RecordSet");
xml.open("GET","index.php",false,"","");
xml.send();
rs.fields.append("a",201,1);
rs.open();
rs.addNew();
rs(0).appendChunk(xml.responseBody);
rs.update();
document.body.innerText=rs("a").value;
rs.close();
document.charset="gbk";
</script>

转载声明: 出自: Ghoul To World!作者: GreatGhoul

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.