-
用ASP来判断用户浏览器类型、版本以及操作系统的类型和版本,以前发过类似的检测程序,今天这个是另一ASP达人所写,希望对你的ASP编码有帮助作用,代码中包括两个函数:GetBrowser()为浏览器类型及版本检测,getsys()为操作系统类型及版本检测。
01<%02'操作系统检测03function getsys()04vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")05if instr(vibo_soft,"Windows NT 5.0") then06msm="Win 2000"07elseif instr(vibo_soft,"Windows NT 5.1") then08msm="Win XP"09elseif instr(vibo_soft,"Windows NT 5.2") then10msm="Win 2003"11elseif instr(vibo_soft,"4.0") then12msm="Win NT"13elseif instr(vibo_soft,"NT") then14msm="Win NT"15elseif instr(vibo_soft,"Windows CE") then16msm="Windows CE"17elseif instr(vibo_soft,"Windows 9") then18msm="Win 9x"19elseif instr(vibo_soft,"9x") then20msm="Windows ME"21elseif instr(vibo_soft,"98") then22msm="Windows 98"23elseif instr(vibo_soft,"Windows 95") then24msm="Windows 95"25elseif instr(vibo_soft,"Win32") then26msm="Win32"27elseif instr(vibo_soft,"unix") or instr(vibo_soft,"linux") or instr(vibo_soft,"SunOS") or instr(vibo_soft,"BSD") then28msm="类Unix"29elseif instr(vibo_soft,"Mac") then30msm="Mac"31else32msm="Other"33end if34getsys=msm35EndFunction3637'浏览器类型及版本检测38function GetBrowser()39dim vibo_soft40vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")41Browser="unknown"42version="unknown"43'vibo_soft="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322)"44IfLeft(vibo_soft,7) ="Mozilla"Then'有此标识为浏览器45vibo_soft=Split(vibo_soft,";")46IfInStr(vibo_soft(1),"MSIE")>0Then47Browser="Microsoft Internet Explorer "48version=Trim(Left(Replace(vibo_soft(1),"MSIE",""),6))49ElseIfInStr(vibo_soft(4),"Netscape")>0Then50Browser="Netscape "51tmpstr=Split(vibo_soft(4),"/")52version=tmpstr(UBound(tmpstr))53ElseIfInStr(vibo_soft(4),"rv:")>0Then54Browser="Mozilla "55tmpstr=Split(vibo_soft(4),":")56version=tmpstr(UBound(tmpstr))57IfInStr(version,")") > 0Then58tmpstr=Split(version,")")59version=tmpstr(0)60EndIf61EndIf62ElseIfLeft(vibo_soft,5) ="Opera"Then63vibo_soft=Split(vibo_soft,"/")64Browser="Mozilla "65tmpstr=Split(vibo_soft(1)," ")66version=tmpstr(0)67EndIf68Ifversion<>"unknown"Then69DimTmpstr170Tmpstr1=Trim(Replace(version,".",""))71IfNotIsNumeric(Tmpstr1)Then72version="unknown"73EndIf74EndIf75GetBrowser=Browser &" "& version76Endfunction77%>上述两个函数均无需参数,直接调用即可返回结果。