- Ext JS 3.0 Cookbook
- Jorge Ramon
- 389字
- 2021-04-01 13:43:43
Detecting browsers and platforms used by clients
Although Ext JS is a cross-browser library, there are instances when your application needs to show a different behavior depending on the user's browser or platform. Browser and platform detection are very simple tasks with Ext JS, and this recipe shows how it's done.
How to do it...
You can detect various browsers and platforms used by your clients in the following way:
- You can use
Ext.isChrome
to find out if the detected browser is Chrome:var browser = ""; if (Ext.isChrome) { browser = "Hi! I'm the new kid on the block"; }
- The browsers such as Mozilla and Firefox that use the Gecko rendering engine are detected with
Ext.isGecko, Ext.isGecko2
, andExt.isGecko3:
if (Ext.isGecko) { browser = "Gecko"; } if (Ext.isGecko2) { browser = "Gecko2"; } if (Ext.isGecko3) { browser = "We like Firefox!"; }
- The Internet Explorer versions are flagged by
Ext.isIE, Ext.isIE6, Ext.isIE7
, andExt.isIE8:
if (Ext.isIE) { browser = "IE"; } if (Ext.isIE6) { browser = "Get a decent browser, now!"; } if (Ext.isIE7) { browser = "IE7"; } if (Ext.isIE8) { browser = "IE8"; }
- Opera is detected with
Ext.isOpera:
if (Ext.isOpera) { browser = "Opera"; }
- And finally, Safari is detected with
Ext.isSafari, Ext.isSafari2, Ext.isSafari3
, andExt.isSafari4:
if (Ext.isSafari) { browser = "Safari"; } if (Ext.isSafari2) { browser = "Safari2"; } if (Ext.isSafari3) { browser = "Safari3"; } if (Ext.isSafari4) { browser = "Safari4"; }
- When it comes to platform detection, Adobe's Air is detected with
Ext.isAir:
var platform = ""; if (Ext.isAir) { platform = "Air"; }
- Linux is detected with
Ext.isLinux:
if (Ext.isLinux) { platform = "Linux"; }
- Mac OS is detected with
Ext.isMac:
if (Ext.isMac) { platform = "Mac"; }
- Windows is detected with
Ext.isWindows:
if (Ext.isWindows) { platform = "Windows "; }
As you can imagine, the values for Ext JS's browser and platform type flags are all obtained from parsing the value of the userAgent
property of the JavaScript navigator object.
Use this recipe when you need to alter the features or behavior of your application depending on the browser or platform being used. For example, depending on the platform used, you can provide Mac or Windows versions of a browser plugin; or you can account for rendering differences of various browsers when positioning DOM elements.
- 玩轉微信
- Core Data iOS Essentials
- Apache Maven 3 Cookbook
- Building Websites with Joomla! 1.5
- 3dsMax 2018動畫制作基礎教程(第4版)
- Photoshop+CorelDRAW 字體設計與創意:草圖/實現/包裝(微課版)
- KNIME視覺化數據分析
- 科技繪圖/科研論文圖/論文配圖設計與創作自學手冊:科研動畫篇
- 動畫制作基礎(項目教學版)
- 中文版SolidWorks 2018完全實戰技術手冊
- Microsoft SQL Server 2008 High Availability
- Photoshop CS6圖像處理立體化教程
- 解密AI繪畫與修圖:Stable Diffusion+Photoshop
- Creo 6.0產品設計實例精解
- 案例學:Photoshop電商美工設計