Phonegap web app in regular desktop browsers

前端 未结 18 1723
深忆病人
深忆病人 2020-12-08 02:27

If I develop a web app in phonegap, can the same web app be made to run in regular desktops/laptops inside a browser?

相关标签:
18条回答
  • 2020-12-08 02:38

    Since the phone gap applications are build using JS, HTML and CSS, You can access these HTML file and run in browser. but your code has access to any device specific calls then it will throw error.

    0 讨论(0)
  • 2020-12-08 02:39

    Yes...and no: Your webapp will run in desktop browsers yes, as it is made of html, css and javascript. The phonegap specific javascript calls (accelerometer, compass, file, etc) won't.

    Basically, if you stick to standard yes you will be able to port relatively easily your app to most browser, the job at this point being mostly a work of theming.

    0 讨论(0)
  • 2020-12-08 02:46

    Right now you could use browser platform together with Cordova.

    You could install it using regular Cordova CLI command cordova platform add browser

    Then installing standard Cordova plugins they provide same programming interface as on the device. Forexample take a look at https://github.com/apache/cordova-plugin-camera/#supported-platforms. Howether support not 100% compatible with device, but Cordova team try bring as much as possible compatible solution to browser as a platform

    0 讨论(0)
  • 2020-12-08 02:46

    As Remy said, most of the standard stuff you write will be fine, but you'll need to wrap certain methods that use the camera/accelerometer to see if you're in an app or not.

    Athough a better solution is to use feature detection, as you can upload pictures and use the camera with the HTML input in a mobile website, I'm pretty sure you can access the web cam in certain versions of Desktop Chrome now.

    If you want to build a properly universal app, you'll need to use lots of feature/device detection, or have a central core product, and use something like Git Submodules to include and extend it as a Phonegap app.

    There is no single, easy, standardised way of doing it.

    0 讨论(0)
  • 2020-12-08 02:47

    There is a tool to run any android app on the system. the tool name is 'bluestack' it can run any android app on systems.

    0 讨论(0)
  • 2020-12-08 02:48

    It will definitely run on desktop and on a webserver whatever, IF you do it right.

    I do this with many of my apps and things to note is:

    • CORS is allowed in PhoneGap but may not be on Desktop browsers
    • Cordova/PhoneGap APIs won't work and can throw errors if you try to call them

    Good practice is to wrap your device specific event listeners etc. in the onDeviceReady function as:

        onDeviceReady: function() {
        // Register the device event listeners
        document.addEventListener("backbutton", function (e) {
            console.log("default prevented");
            e.preventDefault();
        }, false );
        document.addEventListener("resume", onDeviceResume, false);
    

    and register that in the initialize function

    document.addEventListener("deviceready", onDeviceReady, false);
    

    Apart from that I use a primitive function to assign the variable "phonegap" that I can reference if I need to know what platform we are on, or if we are desktop (in which case it will be false).

        isPhoneGap: function() {
        var is = false;
        var agent = navigator.userAgent.toLowerCase();
        var path = window.location.href;
        if (path.indexOf("file://") != -1) {
            if (agent.indexOf("android") != -1) {
                is = "android";
            } else if (agent.indexOf("iphone") != -1 || agent.indexOf("ipad") != -1 || agent.indexOf("ipod") != -1) {
                is = "ios";
            } else if (agent.indexOf("iemobile") != -1) {
                is = "wp";
            }
        }
        return is;
    },
    

    Not super pretty but hope this helps.

    0 讨论(0)
提交回复
热议问题