asp(JavaScript)自動判斷網(wǎng)頁編碼并轉(zhuǎn)換的代碼
更新時間:2010年06月03日 13:38:21 作者:
asp轉(zhuǎn)換網(wǎng)頁編碼的代碼,用正則匹配頁面的編碼聲明是gb2312還是別的,然后輸出。
完整的示例代碼如下:
<%@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.dhdzp.com/404.htm"))%>
</body>
</html>
復制代碼 代碼如下:
<%@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.dhdzp.com/404.htm"))%>
</body>
</html>
相關文章
asp刪除mssql數(shù)據(jù)庫中沒有記錄的圖片代碼
asp刪除沒有記錄的圖片需要文件夾(存放圖片的文件夾)中的每個圖片和數(shù)據(jù)庫中的所有記錄進行比較2009-08-08
通過ASP禁止指定IP和只允許指定IP訪問網(wǎng)站的代碼
通過ASP禁止指定IP和只允許指定IP訪問網(wǎng)站的代碼,需要的朋友可以參考下。2011-10-10
檢查access數(shù)據(jù)庫中是否存在某個名字的表的asp代碼
首先調(diào)用adodb.connection對象中的openSchema函數(shù),這樣會得到一個Recordset,其中每一條“紀錄”對應著數(shù)據(jù)庫中的一張表,“紀錄”的每個“字段”包含了對應表的某方面信息。其中TABLE_NAME字段包含了對應表的名稱2009-06-06
asp實現(xiàn)檢查ip地址是否為內(nèi)網(wǎng)或者私有ip地址的代碼分享
這篇文章主要介紹了asp實現(xiàn)檢查ip地址是否為內(nèi)網(wǎng)或者私有ip地址的代碼分享,給同樣在找IP判斷的使用,需要的朋友可以參考下2014-08-08
ASP中字符與數(shù)字內(nèi)置操作函數(shù)整理
在ASP中,預定義了許多函數(shù),可以幫助我們簡化代碼、提高開發(fā)效率,本文將介紹一些常用的ASP字符與數(shù)字內(nèi)置操作函數(shù),以便開發(fā)人員更加方便、快速地創(chuàng)建 Web 應用程序,2023-12-12

