1 Object: Browser {#Browser}
2 ==========================
4 Some browser properties are attached to the Browser Object for browser and platform detection.
6 Browser.Features {#Browser:Browser-Features}
7 --------------------------------------------
9 * Browser.Features.xpath - (*boolean*) True if the browser supports DOM queries using XPath.
10 * Browser.Features.air - (*boolean*) True if the browser supports AIR.
11 * Browser.Features.query - (*boolean*) True if the browser supports querySelectorAll.
12 * Browser.Features.json - (*boolean*) True if the browser has a native JSON object.
13 * Browser.Features.xhr - (*boolean*) True if the browser supports native XMLHTTP object.
15 Browser.Request {#Browser:Browser-Request}
16 ------------------------------------------
18 * Browser.Request - (*object*) The XMLHTTP object or equivalent.
20 Browser.exec {#Browser:Browser-exec}
21 ------------------------------------
23 Executes the passed in string in the browser context.
27 Browser.exec('alert("Moo!");');
29 Browser.parseUA {#Browser:Browser-parseUA}
30 ------------------------------------------
32 A function to parse a user agent string to an object, intended for informational or statistical purposes. If also passed a platform string, it will use that string in addition to the user agent to attempt to determine the platform.
34 The results of this function for the currently active user agent and platform strings are saved on the Browser object upon load. See below.
36 For more information regarding User Agent detection, please refer to the [Deprecated section](#Deprecated).
40 var parsed = Browser.parseUA(userAgentString[, platformString]);
44 1. userAgentString - (*string*) A user agent string, like the one found in `window.navigator.userAgent`.
45 2. platformString - (*string*, optional) A platform string, like the one found in `window.navigator.platform`.
49 * (*object*) - An object containing information parsed from the strings passed.
53 console.log(Browser.parseUA("Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20140319 Firefox/24.0 Iceweasel/24.4.0", "Linux x86_64"));
55 // This logs: {name: "firefox", version: 24, platform: "linux"}
57 Browser.name {#Browser:Browser-name}
58 ------------------------------------
60 'Browser.name' reports the name found in the Browser's userAgent string as string, intended for informational or statistical purposes. See [Browser.parseUA](#Browser:Browser-parseUA).
64 alert(Browser.name); // Alerts "ie" in Internet Explorer, "firefox" in Mozilla Firefox, "chrome" in Google Chrome, "safari" or "opera".
66 Browser.version {#Browser:Browser-version}
67 ------------------------------------------
69 'Browser.version' reports the version found in the Browser's userAgent string as number, intended for informational and statistical purposes. See [Browser.parseUA](#Browser:Browser-parseUA).
73 alert(Browser.version); // Alerts '33' in Chrome 33.0.1750.152
75 Browser.platform {#Browser:Browser-platform}
76 --------------------------------------------
78 'Browser.platform' reports the platform found in the Browser's userAgent or platform string as string, intended for informational and statistical purposes. See [Browser.parseUA](#Browser:Browser-parseUA).
82 alert(Browser.platform); // Alerts 'mac' on OS X 10.9 Mavericks
85 Deprecated {#Deprecated}
86 ========================
88 ### User Agent detection
90 The features described below use user agent detection (either the userAgent string or platform string) to determine values or properties aimed at activating/deactivating functionality easily. You are encouraged to use other ways of reaching your goal, like feature detection (`Browser.Features`, your own or [has.js](https://github.com/phiggins42/has.js)), progressive enhancement (the act of having the least compatible features "on top", so the other features still work) and/or graceful degredation (building with all features, but tweaking to have non-compatible things "fall back").
94 - [MDN about Browser detection using the user agent](https://developer.mozilla.org/en-US/docs/Browser_detection_using_the_user_agent)
96 Browser[Browser.name] {#Browser:Browser-Browser-name}
97 -----------------------------------------------------
99 **Important note:** These properties are deprecated since MooTools 1.5, and are only available in the 1.4-compatibility version.
101 The name found in the Browser's userAgent string is stored as property names of the following Boolean values:
103 * Browser.ie - (*boolean*) True if the current browser is Internet Explorer.
104 * Browser.firefox - (*boolean*) True if the current browser is Firefox.
105 * Browser.safari - (*boolean*) True if the current browser is Safari.
106 * Browser.chrome - (*boolean*) True if the current browser is Chrome.
107 * Browser.opera - (*boolean*) True if the current browser is Opera.
109 In addition to one of the above properties a second property consisting of the name and the major version is provided ('Browser.ie6', 'Browser.chrome15', ...).
111 If 'Browser.chrome' is True, all other possible properties, like 'Browser.firefox', 'Browser.ie', ... , will be `undefined`.
116 // This code will only run in IE
119 if (Browser.firefox24){
120 // This code will only run in Firefox 24
123 if (Browser.ie6 || Browser.ie7){
124 // Please upgrade your browser
127 If an IE document is set to backward compatibility mode using the X-UA-Compatible header, then the Browser object is treated as if the earlier version of the browser is running.
129 ### Special note about Browser.ie:
131 In the compatibility build, for IE>=11, `Browser.ie` will remain `undefined`. See below:
133 The primary use of `Browser.ie` is activating "legacy code", such "legacy code" is no longer required in more recent versions of Internet Explorer (and may not even work anymore). Changing `Browser.ie == true` for modern IE (IE >= 11) in the compatibility build would do more harm than good, even though it's technically correct. Since we did not want to break existing projects that have come to rely on `Browser.ie` not being true for the newer version(s) of IE, the compatibility build will not set `Browser.ie` for these versions of IE. However, `Browser.ie11` will work correctly and `Browser.name` will equal "ie".
135 Browser.Platform {#Browser:Browser-Platform}
136 --------------------------------------------
138 **Important note:** The *Browser.Platform* object is deprecated since MooTools 1.5, and is only available in the 1.4-compatibility version.
140 * Browser.Platform.mac - (*boolean*) True if the platform is Mac.
141 * Browser.Platform.win - (*boolean*) True if the platform is Windows.
142 * Browser.Platform.linux - (*boolean*) True if the platform is Linux.
143 * Browser.Platform.ios - (*boolean*) True if the platform is iOS.
144 * Browser.Platform.android - (*boolean*) True if the platform is Android
145 * Browser.Platform.webos - (*boolean*) True if the platform is WebOS
146 * Browser.Platform.other - (*boolean*) True if the platform is neither Mac, Windows, Linux, Android, WebOS nor iOS.
147 * Browser.Platform.name - (*string*) The name of the platform.
149 Browser.Plugins {#Browser:Browser-Plugins}
150 ------------------------------------------
152 **Important note:** The *Browser.Plugins* object is deprecated since MooTools 1.5, and is only available in the 1.4-compatibility version.
154 * Browser.Plugins.Flash - (*object*) - An object with properties corresponding to the `version` and `build` number of the installed Flash plugin. Note: if flash is not installed, both `Browser.Plugins.Flash.version` and `Browser.Plugins.Flash.build` will return zero.
155 * Browser.Plugins.Flash.version - (*number*) The major version of the flash plugin installed.
156 * Browser.Plugins.Flash.build - (*number*) The build version of the flash plugin installed.
158 Browser.Engine {#Browser:Browser-Engine}
159 ----------------------------------------
161 **Important note:** The *Browser.Engine* object is deprecated since MooTools 1.3, and is only available in the 1.2-compatibility version.
165 * Browser.Engine.trident - (*boolean*) True if the current browser uses the trident engine (e.g. Internet Explorer).
166 * Browser.Engine.gecko - (*boolean*) True if the current browser uses the gecko engine (e.g. Firefox, or any Mozilla Browser).
167 * Browser.Engine.webkit - (*boolean*) True if the current browser uses the webkit engine (e.g. Safari, Google Chrome, Konqueror).
168 * Browser.Engine.presto - (*boolean*) True if the current browser uses the presto engine (e.g. Opera 9).
169 * Browser.Engine.name - (*string*) The name of the engine.
170 * Browser.Engine.version - (*number*) The version of the engine. (e.g. 950)