欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp(JavaScript)自動判斷網(wǎng)頁編碼并轉(zhuǎn)換的代碼

 更新時間:2010年06月03日 13:38:21   作者:  
asp轉(zhuǎn)換網(wǎng)頁編碼的代碼,用正則匹配頁面的編碼聲明是gb2312還是別的,然后輸出。
完整的示例代碼如下:
復(fù)制代碼 代碼如下:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>JavaScript自動判斷網(wǎng)頁編碼并轉(zhuǎn)換</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"}//對獲取不到的網(wǎng)站采用gb2312編碼,可自行更改
//自動判斷編碼結(jié)束
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.dbjr.com.cn/404.htm"))%>
</body>
</html>

相關(guān)文章

最新評論