官术网_书友最值得收藏!

Detecting the device

Different devices offer different capabilities and hence for an application developer, it becomes important to identify the exact device, so that it can respond to the events in the most appropriate way. This recipe describes how we can detect the device on which the application is being run.

How to do it...

Carry out the following steps:

  1. Create and open a new file ch01_02.js in the ch01 folder and paste the following code into it:
    Ext.setup({
      onReady: function() {
        if (Ext.is.Android)
          Ext.Msg.alert("INFO", "Welcome Android user!");
          
        if (Ext.is.Blackberry)
          Ext.Msg.alert("INFO", "Welcome Blackberry user!");
          
        if (Ext.is.iPad)
          Ext.Msg.alert("INFO", "Welcome iPad user!");
      }
    });
  2. Remove the following line from index.html:
    <script type="text/javascript" charset="utf-8" src="ch01/ch01_01.js"></script>
  3. Include the following line in index.html:
    <script type="text/javascript" charset="utf-8" src="ch01/ch01_02.js"></script>
  4. Deploy and run the application. Based on the device on which the application is being run, you will see a corresponding message.

How it works...

The Ext.is class is instrumental in detecting the target device on which your application is being run. It uses the JavaScript's navigator object to detect the browser details, including the platform/device. For example, if the platform property in the navigator object has iPhone in it, then the target platform is iPhone, whereas if the userAgent property in the navigator object has Android, then the platform is Android.

See also

  • The recipe named Setting up the browser-based development environment in this chapter
  • The recipe named Setting up the production environment in this chapter
主站蜘蛛池模板: 安塞县| 南汇区| 青河县| 仙游县| 苍南县| 乌海市| 乌兰县| 襄城县| 呼伦贝尔市| 尚志市| 吉木萨尔县| 莫力| 岑溪市| 凌海市| 仪陇县| 北宁市| 青州市| 鄂伦春自治旗| 府谷县| 霍州市| 枞阳县| 澄迈县| 兴城市| 田林县| 黄平县| 平顺县| 凯里市| 宁武县| 庄河市| 凌海市| 忻城县| 南华县| 奇台县| 临潭县| 二手房| 科技| 宣威市| 吉安县| 松原市| 承德县| 乌拉特前旗|