<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JavaScript自动判断网页编码并转换</title>
</head>
<%server.ScriptTimeout=9999999;
function send_request(url){
var codedtext;
HTTP_Request = Server.CreateObject("Microsoft.XMLHTTP");
HTTP_Request.Open("GET",url,false);
HTTP_Request.Send(null);
if (HTTP_Request.ReadyState == 4){
//自动判断编码开始
var charresult = HTTP_Request.ResponseText.match(/CharSet=(\S+)\">/i);
if (charresult != null){
var Cset = charresult[1];
}else{Cset = "gb2312"}//对获取不到的网站采用gb2312编码,可自行更改
//自动判断编码结束
codedtext = bytesToBSTR(HTTP_Request.Responsebody,Cset);
}else{
codedtext = "Erro";
}
return(codedtext);
}
function bytesToBSTR(body,Cset){
var objstream;
objstream = Server.CreateObject("Adodb.Stream");
objstream.Type = 1;
objstream.Mode = 3;
objstream.open();
objstream.Write(body);
objstream.Position = 0;
objstream.Type = 2;
objstream.Charset = Cset;
bytesToBSTR = objstream.Readtext;
objstream.Close;
return(bytesToBSTR);
}%>
<body>
<%response.Write(send_request("http://www.jb51.net/404.htm"))%>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。