<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- 作者:小林,sulins@tom.com -->
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
</HEAD>
<script language=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
Function viewSource1()
dim XmlHttp
set XmlHttp = CreateObject("Microsoft.XMLHTTP")
XmlHttp.Open "GET", document.location.href, false
XmlHttp.setRequestHeader "Content-Type","text/XML"
XmlHttp.Send
dim html
html = bytes2BSTR(XmlHttp.responseBody)
msgbox html
End Function
Function viewSource2()
dim XmlHttp
set XmlHttp = CreateObject("Microsoft.XMLHTTP")
XmlHttp.Open "GET", "http://www.google.com", false
XmlHttp.setRequestHeader "Content-Type","text/XML"
XmlHttp.Send
dim html
html = bytes2BSTR(XmlHttp.responseBody)
msgbox html
End Function
</script>
<BODY bgcolor=gainsboro style='border:1pt solid white'>
<TABLE class=text>
<tr>
<td class=text>XMLHTTP Get HTML页面时的中文乱码之完全客户端Script解决方案</td>
</tr>
<tr>
<td class=button><button onclick=viewSource1()>查看自身的网页代码</button></td>
</tr>
<tr>
<td class=button><button onclick=viewSource2()>查看google主页代码</button></td>
</tr>
</TABLE>
</BODY>
</HTML>