ASP 判断浏览器的类型与版本号

2012-07-13 11:25:46

Function getBrowser(strUA) Dim arrInfo Dim Matches,regEx, Match, SubMatches, SMatch, regExResult arrInfo = Array("Unkown", "Unkown") Set regEx = New RegExp ' 建立正则表达式。 regEx.Pattern = "(opera|ie|firefox|chrome|version)[\s\/:]([\w\d\.]+)?.*?(safari|version[\s\/:]([\w\d\.]+)|$)" ' 设置模式。 regEx.IgnoreCase = true ' 设置是否区分字符大小写。 regEx.Global = True ' 设置全局可用性。 regExResult = "" Set Matches = regEx.execute(LCase(strUA)) For Each Match In Matches Set SubMatches = Match.SubMatches If Not IsEmpty(SubMatches(0)) Then regExResult = SubMatches(0) If Not IsEmpty(SubMatches(1)) Then regExResult = regExResult & "(" & SubMatches(1) & ")" If Not IsEmpty(SubMatches(2)) And Trim(SubMatches(2))<>"" Then regExResult = regExResult & "[" & SubMatches(2) & "]" End If End If End If Next If Not IsEmpty(regExResult) Then arrInfo(0) = regExResult getBrowser = arrInfo End Function strUA是浏览的UA信息, 正则表达式来自 [url=http://baike.baidu.com/view/1138523.htm]Moo库[/url]