/mojoPortal.Web.Framework/BrowserHelper.cs
C# | 249 lines | 168 code | 70 blank | 11 comment | 96 complexity | 4715b1059c92a694d941e40dd2e5a1b1 MD5 | raw file
Possible License(s): CPL-1.0, CC-BY-SA-3.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause, Apache-2.0
- // Author: Joe Audette
- // Created: 2009-06-29
- // Last Modified: 2012-06-18
- //
- // The use and distribution terms for this software are covered by the
- // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
- // which can be found in the file CPL.TXT at the root of this distribution.
- // By using this software in any fashion, you are agreeing to be bound by
- // the terms of this license.
- //
- // You must not remove this notice, or any other, from this software.
-
- using System;
- using System.Collections.Generic;
- using System.Web;
-
-
- namespace mojoPortal.Web.Framework
- {
- 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;
-
- }
-
- public static bool IsIOS5()
- {
- bool result = false;
-
- if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
- {
- result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("os 5_"));
- }
-
-
- return result;
-
- }
-
- public static bool MobileDeviceSupportsWYSIWYG()
- {
- bool result = false;
-
- if (
- (IsIpad() || IsIphone())
- &&(IsIOS5())
- )
- {
- 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;
-
- }
-
- }
- }