ブラウザ名とバージョン番号を取得
3488 ワード
:Javascript:
function GetBrowserInfo() {
var agency = navigator.userAgent;
var temp;
var match = agency.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(match[1])) {
temp = /\brv[ :]+(\d+)/g.exec(agency) || [];
return { name: 'IE', version: (temp[1] || '') };
}
if (match[1] == "Chrome") {
temp = agency.match(/\bOPR\/(\d+)/);
if (temp != null) {
return { name: 'Opera', version: temp[1] };
}
}
match = match[2] ? [match[1], match[2]] : [navigator.appName, navigator.appVersion, '-?'];
if (temp = agency.match(/version\/(\d+)/i) != null) {
match.slice(1, 1, temp[1]);
}
return { name: match[0], version: match[1] };
}
var browser = GetBrowserInfo();
alert(" : " + browser.name + "\r" + " : " + browser.version);
方法の2:C〓〓〓〓 public static string GetBrowserInfo()
{
//HttpBrowserCapabilities hbc = HttpContext.Current.Request.Browser;
//string browserName = hbc.Browser.ToString();
//string browserVersion = hbc.Version.ToString();
//return string.Format(" : " + browserName + "\r" + " : " + browserVersion);
System.Web.HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
return "Browser Capabilities
"
+ "Type = " + browser.Type + "<br>"
+ "Name = " + browser.Browser + "<br>"
+ "Version = " + browser.Version + "<br>"
+ "Major Version = " + browser.MajorVersion + "<br>"
+ "Minor Version = " + browser.MinorVersion +"<br>"
+ "Platform = " + browser.Platform + "<br>"
+ "Is Beta = " + browser.Beta + "<br>"
+ "Is Crawler = " + browser.Crawler + "<br>"
+ "Is AOL = " + browser.AOL + "<br>"
+ "Is Win16 = " + browser.Win16 + "<br>"
+ "Is Win32 = " + browser.Win32 + "<br>"
+ "Supports Frames = " + browser.Frames + "<br>"
+ "Supports Tables = " + browser.Tables + "<br>"
+ "Supports Cookies = " + browser.Cookies + "<br>"
+ "Supports VBScript = " + browser.VBScript + "<br>"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "<br>"
+ "Supports Java Applets = " + browser.JavaApplets + "<br>"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "<br>"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "<br>";
}