PhoneGap: Detect if running on desktop browser

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

    Just for info the way in PhoneGap 3.x Mobile Application Development Hotshot

    var userLocale = "en-US";
    function startApp()
    {
    // do translations, format numbers, etc.
    }
    function getLocaleAndStartApp()
    {
        navigator.globalization.getLocaleName (
            function (locale) {
                userLocale = locale.value;
                startApp();
            },
            function () {
                // error; start app anyway
                startApp();
            });
    }
    function executeWhenReady ( callback ) {
        var executed = false;
        document.addEventListener ( "deviceready", function () {
            if (!executed) {
                executed = true;
                if (typeof callback === "function") {
                    callback();
                }
            }
        }, false);
        setTimeout ( function () {
            if (!executed) {
                executed = true;
                if (typeof callback === "function") {
                    callback();
                }
            }
        }, 1000 );
    };
    executeWhenReady ( function() {
        getLocaleAndStartApp();
    } );
    

    and in YASMF framework

    https://github.com/photokandyStudios/YASMF-Next/blob/master/lib/yasmf/util/core.js#L152

提交回复
热议问题