Browser detection

前端 未结 6 1442
春和景丽
春和景丽 2020-11-30 00:35

I need to separate IE and FF browsers from others

it\'s a pseudo-code :

If (CurrentBrowser == IE(6+) or FF(2+) )
{
...
}
else 
{
...
}
相关标签:
6条回答
  • 2020-11-30 00:47

    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

    0 讨论(0)
  • 2020-11-30 00:47
        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;
        }
    
    0 讨论(0)
  • 2020-11-30 00:53

    use from

    Request.Browser
    

    this link will help you :

    Detect the browser using ASP.NET and C#

    0 讨论(0)
  • 2020-11-30 00:55

    I would not advise hacking browser-specific things manually with JS. Either use a javascript library like "prototype" or "jquery", which will handle all the specific issues transparently.

    Or use these libs to determine the browser type if you really must.

    Also see Browser & version in prototype library?

    0 讨论(0)
  • 2020-11-30 01:04
    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 { }
    
    0 讨论(0)
  • 2020-11-30 01:09

    Try the below code

    HttpRequest req = System.Web.HttpContext.Current.Request
    string browserName = req.Browser.Browser;
    
    0 讨论(0)
提交回复
热议问题