真的通过C#.NET 2.0或更高版本检测浏览器支持Javascript?

时间:2011-08-26 04:16:50

标签: javascript

我需要检测浏览器是否支持C#.NET 2.0代码的Javascript。但Request.Browser.Javascript现在对所有浏览器都无法正常工作。

我真的需要其他方法来检测它,谁能告诉我也知道每个人都有同样的问题。

谢谢: - )

3 个答案:

答案 0 :(得分:0)

请改用new HttpBrowserCapabilities().JavaScript

答案 1 :(得分:0)

当您说C#.NET 2.0代码时,您指的是ASP.NET还是Silverlight?我假设ASP.NET。无论如何,浏览器检测是关于客户端功能的非常不可靠的信息源。你真的想知道什么?如果您需要确保客户端启用了Javascript,则一种方法是包含html代码,例如<noscript>This page requires javascript</noscript>。这是提供回退错误信息的一种非常常见的方式(即您的代码需要Javascript才能正常工作)。

答案 2 :(得分:0)

Scott Hanselman博客上查看此链接,它会按照您的建议描述问题。另请查看此MSDN链接。

来自MSDN的代码示例:

private void Button1_Click(object sender, System.EventArgs e)
{
    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"
        + "Supports JavaScript Version = " +
            browser["JavaScriptVersion"] + "\n";

    TextBox1.Text = s;
}

我强烈希望它能解决你的问题。