- 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.
- GIMP 2.6 cookbook
- 中文版AutoCAD 2016從入門到精通
- Photoshop后期強:數(shù)碼攝影后期完全寶典
- Excel 2013使用詳解(修訂版)
- Photoshop數(shù)碼攝影后期處理專業(yè)技法(第2版)
- VSTO 3.0 for Office 2007 Programming
- SPSS進階分析與實務
- 3ds Max 2015中文版從入門到精通
- 正則表達式必知必會(修訂版)
- Backbone.js Cookbook
- 好學、好用、好玩的Photoshop 寫給初學者的入門書(第4版)
- 剪映+Vlog+Premiere短視頻制作從新手到高手
- iOS智能手機APP界面設計實戰(zhàn)教程
- 3ds Max-Photoshop游戲模型制作全攻略
- FLUENT 15.0流場分析實戰(zhàn)指南