PhoneGap: Detect if running on desktop browser

后端 未结 30 2862
时光取名叫无心
时光取名叫无心 2020-11-29 15:47

I\'m developing a web application that uses PhoneGap:Build for a mobile version and want to have a single codebase for the \'desktop\' and mobile versions. I want to be able

30条回答
  •  清歌不尽
    2020-11-29 16:09

    I've actually found a combination of two of the techniques listed here has worked the best, firstly check that cordova / phonegap can be accessed also check if device is available. Like so:

    function _initialize() {
        //do stuff
    }
    
    if (window.cordova && window.device) {
        document.addEventListener('deviceready', function () {
          _initialize();
        }, false);
    } else {
       _initialize();
    }
    

提交回复
热议问题