首页 > 代码库 > 浏览器信息
浏览器信息
1 using System; 2 using System.Net; 3 using System.Windows; 4 using System.Windows.Browser; 5 using System.Windows.Controls; 6 using System.Windows.Documents; 7 using System.Windows.Ink; 8 using System.Windows.Input; 9 using System.Windows.Media; 10 using System.Windows.Media.Animation; 11 using System.Windows.Shapes; 12 13 namespace TWSL.Common 14 { 15 /// <summary> 16 /// 浏览器屏幕信息类 17 /// </summary> 18 public class Browser 19 { 20 /// <summary> 21 /// During static instantiation, only the Netscape flag is checked 22 /// </summary> 23 static Browser() 24 { 25 _isNavigator = HtmlPage.BrowserInformation.Name.Contains("Netscape"); 26 } 27 28 /// <summary> 29 /// Flag indicating Navigator/Firefox/Safari or Internet Explorer 30 /// </summary> 31 private static bool _isNavigator; 32 33 /// <summary> 34 /// Provides quick access to the window.screen ScriptObject 35 /// </summary> 36 private static ScriptObject Screen 37 { 38 get 39 { 40 ScriptObject screen = (ScriptObject)HtmlPage.Window.GetProperty("screen"); 41 42 if (screen == null) 43 { 44 throw new InvalidOperationException(); 45 } 46 47 return screen; 48 } 49 } 50 51 /// <summary> 52 /// Gets the window object‘s client width 53 /// </summary> 54 public static double ClientWidth 55 { 56 get 57 { 58 return _isNavigator ? (double)HtmlPage.Window.GetProperty("innerWidth") 59 : (double)HtmlPage.Document.Body.GetProperty("clientWidth"); 60 } 61 62 } 63 64 /// <summary> 65 /// Gets the window object‘s client height 66 /// </summary> 67 public static double ClientHeight 68 { 69 get 70 { 71 return _isNavigator ? (double)HtmlPage.Window.GetProperty("innerHeight") 72 : (double)HtmlPage.Document.Body.GetProperty("clientHeight"); 73 } 74 } 75 76 /// <summary> 77 /// Gets the current horizontal scrolling offset 78 /// </summary> 79 public static double ScrollLeft 80 { 81 get 82 { 83 return _isNavigator ? (double)HtmlPage.Window.GetProperty("pageXOffset") 84 : (double)HtmlPage.Document.Body.GetProperty("scrollLeft"); 85 } 86 } 87 88 /// <summary> 89 /// Gets the current vertical scrolling offset 90 /// </summary> 91 public static double ScrollTop 92 { 93 get 94 { 95 return _isNavigator ? (double)HtmlPage.Window.GetProperty("pageYOffset") 96 : (double)HtmlPage.Document.Body.GetProperty("scrollHeight"); 97 } 98 } 99 100 /// <summary> 101 /// Gets the width of the entire display 102 /// </summary> 103 public static double ScreenWidth104 {105 get106 {107 return (double)Screen.GetProperty("width");108 }109 }110 111 /// <summary> 112 /// Gets the height of the entire display 113 /// </summary> 114 public static double ScreenHeight115 {116 get117 {118 return (double)Screen.GetProperty("height");119 }120 }121 122 /// <summary> 123 /// Gets the width of the available screen real estate, excluding the dock 124 /// or task bar 125 /// </summary> 126 public static double AvailableScreenWidth127 {128 get129 {130 return (double)Screen.GetProperty("availWidth");131 }132 }133 134 /// <summary> 135 /// Gets the height of the available screen real estate, excluding the dock 136 /// or task bar 137 /// </summary> 138 public static double AvailableScreenHeight139 {140 get141 {142 return (double)Screen.GetProperty("availHeight");143 }144 }145 146 /// <summary> 147 /// Gets the absolute left pixel position of the window in display coordinates 148 /// </summary> 149 public static double ScreenPositionLeft150 {151 get152 {153 return _isNavigator ? (double)HtmlPage.Window.GetProperty("screenX")154 : (double)HtmlPage.Window.GetProperty("screenLeft");155 }156 }157 158 /// <summary> 159 /// Gets the absolute top pixel position of the window in display coordinates 160 /// </summary> 161 public static double ScreenPositionTop162 {163 get164 {165 return _isNavigator ? (double)HtmlPage.Window.GetProperty("screenY")166 : (double)HtmlPage.Window.GetProperty("screenTop");167 }168 }169 170 }171 }
浏览器信息
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。