浏览器检测
我需要将IE和FF浏览器与其他人分开
这是一个伪代码:
If (CurrentBrowser == IE(6+) or FF(2+) ) { ... } else { ... }
在protected void Page_Load()
事件(这样想)
if ((Request.Browser.Type == "IE") || (Request.Browser.Type == "FF")) { WebMsgBox.Show("1111"); }
没有效果: – 什么是IE和FFtypes?
if (Request.Browser.Type.Contains("Firefox")) // replace with your check { ... } else if (Request.Browser.Type.ToUpper().Contains("IE")) // replace with your check { if (Request.Browser.MajorVersion < 7) { DoSomething(); } ... } else { }
这里有一种方法可以请求关于正在使用的浏览器的信息,你可以用它来做你的if语句
System.Web.HttpBrowserCapabilities browser = Request.Browser; string s = "Browser Capabilities\n" + "Type = " + browser.Type + "\n" + "Name = " + browser.Browser + "\n" + "Version = " + browser.Version + "\n" + "Major Version = " + browser.MajorVersion + "\n" + "Minor Version = " + browser.MinorVersion + "\n" + "Platform = " + browser.Platform + "\n" + "Is Beta = " + browser.Beta + "\n" + "Is Crawler = " + browser.Crawler + "\n" + "Is AOL = " + browser.AOL + "\n" + "Is Win16 = " + browser.Win16 + "\n" + "Is Win32 = " + browser.Win32 + "\n" + "Supports Frames = " + browser.Frames + "\n" + "Supports Tables = " + browser.Tables + "\n" + "Supports Cookies = " + browser.Cookies + "\n" + "Supports VBScript = " + browser.VBScript + "\n" + "Supports JavaScript = " + browser.EcmaScriptVersion.ToString() + "\n" + "Supports Java Applets = " + browser.JavaApplets + "\n" + "Supports ActiveX Controls = " + browser.ActiveXControls + "\n";
MSDN文章
private void BindDataBInfo() { System.Web.HttpBrowserCapabilities browser = Request.Browser; Literal1.Text = "<table border=\"1\" cellspacing=\"3\" cellpadding=\"2\">"; foreach (string key in browser.Capabilities.Keys) { Literal1.Text += "<tr><td>" + key + "</td><td>" + browser[key] + "</tr>"; } Literal1.Text += "</table>"; browser = null; }
我不会build议用JS手动攻击浏览器特定的东西。 要么使用像“原型”或“jquery”,这将透明地处理所有的具体问题的JavaScript库。
或者如果你真的必须使用这些库来确定浏览器的types。
另请参阅原型库中的浏览器和版本?
使用
Request.Browser
这个链接将帮助你:
使用ASP.NET和C#检测浏览器