Print Shortlink

Loading PhoneGap library for different devices

Maintaining single codebase while building native mobile applications is one of the reasons for using PhoneGap. PhoneGap provides a separate JavaScript library for different devices. Based on the device you have to load the appropriate PhoneGap JS files.
Say, your application is targeting the Android, iPhone and Blackberry platforms, you can have the PhoneGap JS file (phonegap-versionNumber.js in the earlier versions and cordova-versionNumber.js in the current version) provided for each of these platforms renamed to
phoneGap-android.js, phoneGap-iphone.js, phonegap-blackberry.js (or)
cordova-android.js, cordova-iphone.js, cordova-blackberry.js

Based on the device that is accessing the application one of these three files can be loaded like shown below.

var userAgent = navigator.userAgent.toLowerCase();

if (userAgent.match(/android/)) {
        document.write("<script src='phonegap-android.js'></script>");
    } 
    else if (userAgent.match(/iphone/)){
        document.write("<script src='phonegap-iphone.js'></script>");
    }
    else if (userAgent.match(/blackberry/)){{
        document.write("<script src='phonegap-blackberry.js'></script>"); 
    }
Page 1 of 1

One Response

  1. Google

    Google…

    […]Sites of interest we have a link to[…]…

Leave a Reply