PageRenderTime 80ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/mojoPortal.Web.Framework/BrowserHelper.cs

http://mojoportal.codeplex.com
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
  1. // Author: Joe Audette
  2. // Created: 2009-06-29
  3. // Last Modified: 2012-06-18
  4. //
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. // which can be found in the file CPL.TXT at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Web;
  15. namespace mojoPortal.Web.Framework
  16. {
  17. public static class BrowserHelper
  18. {
  19. private const string IE = "IE";
  20. private const string Version6 = "6";
  21. private const string Version7 = "7";
  22. private const string Version8 = "8";
  23. private const string Version9 = "9";
  24. public static bool IsIE6()
  25. {
  26. bool result = false;
  27. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
  28. {
  29. HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
  30. if ((browser.Browser == IE) && (browser.Version.StartsWith(Version6)))
  31. {
  32. result = true;
  33. }
  34. }
  35. return result;
  36. }
  37. public static bool IsIE7()
  38. {
  39. bool result = false;
  40. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
  41. {
  42. HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
  43. if ((browser.Browser == IE) && (browser.Version.StartsWith(Version7)))
  44. {
  45. result = true;
  46. }
  47. }
  48. return result;
  49. }
  50. public static bool IsIE8()
  51. {
  52. bool result = false;
  53. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
  54. {
  55. HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
  56. if ((browser.Browser == IE) && (browser.Version.StartsWith(Version8)))
  57. {
  58. result = true;
  59. }
  60. }
  61. return result;
  62. }
  63. public static bool IsIE9()
  64. {
  65. bool result = false;
  66. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.Browser != null))
  67. {
  68. HttpBrowserCapabilities browser = HttpContext.Current.Request.Browser;
  69. if ((browser.Browser == IE) && (browser.Version.StartsWith(Version9)))
  70. {
  71. result = true;
  72. }
  73. }
  74. return result;
  75. }
  76. public static bool IsIE()
  77. {
  78. bool result = false;
  79. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  80. {
  81. if (HttpContext.Current.Request.UserAgent.Contains("MSIE"))
  82. {
  83. result = true;
  84. }
  85. }
  86. return result;
  87. }
  88. public static bool IsFF()
  89. {
  90. bool result = false;
  91. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  92. {
  93. if (HttpContext.Current.Request.UserAgent.Contains("Firefox"))
  94. {
  95. result = true;
  96. }
  97. }
  98. return result;
  99. }
  100. public static bool IsSafari()
  101. {
  102. bool result = false;
  103. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  104. {
  105. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("safari"));
  106. }
  107. return result;
  108. }
  109. public static bool IsOpera()
  110. {
  111. bool result = false;
  112. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  113. {
  114. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("opera"));
  115. }
  116. return result;
  117. }
  118. public static bool IsIphone()
  119. {
  120. bool result = false;
  121. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  122. {
  123. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone"));
  124. }
  125. return result;
  126. }
  127. public static bool IsIpad()
  128. {
  129. bool result = false;
  130. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  131. {
  132. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("ipad"));
  133. }
  134. return result;
  135. }
  136. public static bool IsIOS5()
  137. {
  138. bool result = false;
  139. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  140. {
  141. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("os 5_"));
  142. }
  143. return result;
  144. }
  145. public static bool MobileDeviceSupportsWYSIWYG()
  146. {
  147. bool result = false;
  148. if (
  149. (IsIpad() || IsIphone())
  150. &&(IsIOS5())
  151. )
  152. {
  153. result = true;
  154. }
  155. return result;
  156. }
  157. public static bool IsSmartPhone()
  158. {
  159. bool result = false;
  160. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  161. {
  162. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("iphone"));
  163. if (result) { return result; }
  164. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("android"));
  165. if (result) { return result; }
  166. }
  167. return result;
  168. }
  169. public static bool IsWindowsLiveWriter()
  170. {
  171. bool result = false;
  172. if ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && (HttpContext.Current.Request.UserAgent != null))
  173. {
  174. result = (HttpContext.Current.Request.UserAgent.ToLower().Contains("windows live writer"));
  175. }
  176. return result;
  177. }
  178. }
  179. }