• 常用浏览器后台判断方法


     public static class BrowserHelper
        {
            private const string IE = "IE";
            private const string Version6 = "6";
            private const string Version7 = "7";
            private const string Version8 = "8";
            private const string Version9 = "9";
    
            public static bool IsIE6()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
                {
                    HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
                    if ((browser.Browser == IE) && (browser.Version.StartsWith(Version6)))
                    {
                        result = true;
                    }
                    
                }
    
                return result;
    
            }
    
            public static bool IsIE7()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
                {
                    HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
                    if ((browser.Browser == IE) && (browser.Version.StartsWith(Version7)))
                    {
                        result = true;
                    }
    
                }
    
                return result;
    
            }
    
            public static bool IsIE8()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
                {
                    HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
                    if ((browser.Browser == IE) && (browser.Version.StartsWith(Version8)))
                    {
                        result = true;
                    }
    
                }
    
                return result;
    
            }
    
            public static bool IsIE9()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
                {
                    HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
                    if ((browser.Browser == IE) && (browser.Version.StartsWith(Version9)))
                    {
                        result = true;
                    }
    
                }
    
                return result;
    
            }
    
            public static bool IsIE()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
    
                    if (HttpContext.Current.Request.UserAgent.Contains("MSIE")) 
                    {
                        result = true;
                    }
    
                }
    
                return result;
    
            }
    
            public static bool IsFF()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
    
                    if (HttpContext.Current.Request.UserAgent.Contains("Firefox"))
                    {
                        result = true;
                    }
    
                }
    
                return result;
    
            }
    
            public static bool IsSafari()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("safari"));
                }
    
                return result;
    
            }
    
            public static bool IsOpera()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("opera"));
                }
    
                return result;
    
            }
    
            public static bool IsIphone()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone"));
                }
    
                return result;
    
            }
    
            public static bool IsIpad()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("ipad"));
                }
    
                return result;
    
            }
    
            private static bool IsOldIOS()
            {
                // older ios does not support wysiwyg editors
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    if (HttpContext.Current.Request.UserAgent.ToLower().Contains("os 4_")) { return true; }
                    if (HttpContext.Current.Request.UserAgent.ToLower().Contains("os 3_")) { return true; }
                }
    
               
                return false;
    
            }
    
            public static bool MobileDeviceSupportsWYSIWYG()
            {
                bool result = false;
    
                if (
                    (IsIpad() || IsIphone())
                    && (!IsOldIOS())
                    )
                {
                    result = true;
                }
    
                return result;
            }
    
    
            public static bool IsSmartPhone()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone"));
                    if (result) { return result; }
    
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("android"));
                    if (result) { return result; }
                }
    
                return result;
    
            }
    
            public static bool IsWindowsLiveWriter()
            {
                bool result = false;
    
                if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
                {
                    result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("windows live writer"));
                }
    
                return result;
    
            }
    
        }
    
  • 相关阅读:
    activiti eclipse 插件安装
    mysql 改编码
    ubuntu vim 中文乱码
    mac 打开 原生 ntfs 读写
    ubuntu 防止 ssh 超时
    java http
    UITabBarController的一些基础设置
    [转]mac 10.9.4下配置apache
    数组的排序及筛选
    一个UICollectionView自定义layout的实现
  • 原文地址:https://www.cnblogs.com/qishiguilai/p/3554757.html
Copyright © 2020-2023  润新知