PhoneGap: Detect if running on desktop browser

后端 未结 30 2872
时光取名叫无心
时光取名叫无心 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:19

    This seems to be viable and I have used it in production:

    if (document.location.protocol == "file:") {
        // file protocol indicates phonegap
        document.addEventListener("deviceready", function() { $(initInternal);} , false);
    }
    else {
        // no phonegap, start initialisation immediately
        $(initInternal);
    }
    

    Source: http://tqcblog.com/2012/05/09/detecting-phonegap-cordova-on-startup/

提交回复
热议问题