<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" ><head>
<title>选取页面</title>
<script type="text/javascript">
<!--
var xmlhttp;
function createHTTP()
{
if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}
function GetData(value)
{
createHTTP();
xmlhttp.onreadystatechange = StateChange;
xmlhttp.open("GET", value, false);
xmlhttp.send();
}
function StateChange()
{
if (xmlhttp.readystate == 4)
{
if (xmlhttp.status == 200)
{
document.getElementById('frame1').contentWindow.document.charset="utf-8";
document.getElementById('frame1').contentWindow.document.body.innerHTML =byte2str(xmlhttp.responseBody)
document.getElementById('frame1').contentWindow.document.onmouseup = ShowSelection;
}
}
}
function ShowSelection()
{
var selection = document.getElementById('frame1').contentWindow.document.selection;
document.getElementById('txtShow').value+= selection.createRange().text;
}
function byte2str(data){
var glbEncode = [];
gb2utf8_data = data;
execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(....{2})(....{2})/g,"%$2%$1").replace(/%([A-Z].)%(....{2})/g,"@$1$2");
t=t.split("@");
var i=0,j=t.length,k;
while(++i<j){
k=t[i].substring(0,4);
if(!glbEncode[k]) {
gb2utf8_char = eval("0x"+k);
execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data = gb2utf8_char = null;
return unescape(t.join("%"));
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style></head>
<body >
<table width="200" border="0" align="center" bgcolor="#009900">
<tr>
<td><div align="center">
<strong>输入页面地址:</strong>
<input name="t" type="text" size="50" maxlength="100" id="t" value="http://www.google.cn"/>
<input type="button" name="Submit" accesskey="enter" value="打开页面" onclick="GetData(document.getElementById('t').value)" />
</div></td>
</tr>
<tr>
<td><textarea name="txtShow" cols="120" rows="10" id="txtShow"></textarea></td>
</tr>
<tr>
<td><iframe width="100%" height="800" id="frame1" >
</iframe></td>
</tr>
</table>
</body>
</html>
显示的文字还是乱码
希望高手给我解决
在此谢过了
<html xmlns="http://www.w3.org/1999/xhtml" ><head>
<title>选取页面</title>
<script type="text/javascript">
<!--
var xmlhttp;
function createHTTP()
{
if (window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}
function GetData(value)
{
createHTTP();
xmlhttp.onreadystatechange = StateChange;
xmlhttp.open("GET", value, false);
xmlhttp.send();
}
function StateChange()
{
if (xmlhttp.readystate == 4)
{
if (xmlhttp.status == 200)
{
document.getElementById('frame1').contentWindow.document.charset="utf-8";
document.getElementById('frame1').contentWindow.document.body.innerHTML =byte2str(xmlhttp.responseBody)
document.getElementById('frame1').contentWindow.document.onmouseup = ShowSelection;
}
}
}
function ShowSelection()
{
var selection = document.getElementById('frame1').contentWindow.document.selection;
document.getElementById('txtShow').value+= selection.createRange().text;
}
function byte2str(data){
var glbEncode = [];
gb2utf8_data = data;
execScript("gb2utf8_data = MidB(gb2utf8_data, 1)", "VBScript");
var t=escape(gb2utf8_data).replace(/%u/g,"").replace(/(....{2})(....{2})/g,"%$2%$1").replace(/%([A-Z].)%(....{2})/g,"@$1$2");
t=t.split("@");
var i=0,j=t.length,k;
while(++i<j){
k=t[i].substring(0,4);
if(!glbEncode[k]) {
gb2utf8_char = eval("0x"+k);
execScript("gb2utf8_char = Chr(gb2utf8_char)", "VBScript");
glbEncode[k]=escape(gb2utf8_char).substring(1,6);
}
t[i]=glbEncode[k]+t[i].substring(4);
}
gb2utf8_data = gb2utf8_char = null;
return unescape(t.join("%"));
}
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
-->
</style></head>
<body >
<table width="200" border="0" align="center" bgcolor="#009900">
<tr>
<td><div align="center">
<strong>输入页面地址:</strong>
<input name="t" type="text" size="50" maxlength="100" id="t" value="http://www.google.cn"/>
<input type="button" name="Submit" accesskey="enter" value="打开页面" onclick="GetData(document.getElementById('t').value)" />
</div></td>
</tr>
<tr>
<td><textarea name="txtShow" cols="120" rows="10" id="txtShow"></textarea></td>
</tr>
<tr>
<td><iframe width="100%" height="800" id="frame1" >
</iframe></td>
</tr>
</table>
</body>
</html>
显示的文字还是乱码
希望高手给我解决
在此谢过了
改成utf-8第二,用记事本打开你的文件,保存时,编码选择utf-8试试