Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser detection

I need to separate IE and FF browsers from others

it's a pseudo-code :

If (CurrentBrowser == IE(6+) or FF(2+) ) { ... } else  { ... } 

in protected void Page_Load() event (think so)

if ((Request.Browser.Type == "IE") || (Request.Browser.Type == "FF")) {     WebMsgBox.Show("1111"); } 

no effects :-/ what is IE and FF types?

like image 516
cnd Avatar asked Feb 08 '10 13:02

cnd


People also ask

What is the importance of browser detection?

Browser sniffing (also known as browser detection) is a set of techniques used in websites and web applications in order to determine the web browser a visitor is using, and to serve browser-appropriate content to the visitor. It is also used to detect mobile browsers and send them mobile-optimized websites.

What is meant by feature detection in a web browser?

Feature detection involves working out whether a browser supports a certain block of code, and running different code depending on whether it does (or doesn't), so that the browser can always provide a working experience rather than crashing/erroring in some browsers.

Is my browser up to date?

Open Chrome and select the Chrome menu, represented by three vertical dots in the top-right corner. If your browser is not up to date you will see an “arrow” where the “dots” should be.


2 Answers

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 { } 
like image 98
Asad Avatar answered Sep 23 '22 05:09

Asad


Here's a way you can request info about the browser being used, you can use this to do your if statement

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 Article

like image 40
Tony The Lion Avatar answered Sep 19 '22 05:09

Tony The Lion