Remote download of the Cordova / PhoneGap application

Regarding Cordoba 3.4:

I came across various messages on the Internet about how to do a remote webpage download using cordova / phonegap, and I could not get it to work. I read questions # 28 and # 29 on github and various other posts.

I load the url directly through setting the content in config.xml (the example below is on my local dev machine, but it doesn’t matter which URL I use in our corporate firewall). I also tried to make window.location for url, but this does not work either.

<content src="http://192.168.96.97:3004/#reference" />

The page loads fine, except when the deviceready event does not fire. The www files local to the cordova application have simply not been deleted.

I get:

deviceready has not fired after 5 seconds.    cordova.js?body=1:1117
Channel not fired: onCordovaInfoReady         cordova.js?body=1:1110
Channel not fired: onCordovaConnectionReady   cordova.js?body=1:1110

Here is my code:

<html><head>
<title>Cordova Test</title>
<script src="cordova.js"></script>
<script src="cordova_plugins.js"></script>
<script src="plugins/org.apache.cordova.device/www/device.js"></script>
<script src="plugins/org.apache.cordova.geolocation/www/Coordinates.js"></script>
<script src="plugins/org.apache.cordova.geolocation/www/PositionError.js"></script>
<script src="plugins/org.apache.cordova.geolocation/www/Position.js"></script>
<script src="plugins/org.apache.cordova.geolocation/www/geolocation.js"></script>
<script src="plugins/org.apache.cordova.network-information/www/network.js"></script>
<script src="plugins/org.apache.cordova.network-information/www/Connection.js></script>
<script>

    // Wait for device API libraries to load
    function onLoad() {
        alert("onload..."); // this displays
        document.addEventListener("deviceready", onDeviceReady, false);
    }

    // device APIs are available
    function onDeviceReady() { // this never fires
        // Now safe to use device APIs
        alert("deviceready...");
        console.log("deviceready...");
    }

</script>
</head>
<body onload="onLoad();" style="">
    hello! :)
</body></html>

Thank!

+4
source share
1 answer

Do not wait for onload to catch fire before adding a deviceready event listener. I suspect that deviceready has already been fired and therefore you are not calling your handler. Even if the cord is not loaded, it contains logic to run even for listeners registered before it was downloaded.

In addition, cordova will add script tags to load its own dependencies, so you only need to add the cordova.js script tag.

0
source

Source: https://habr.com/ru/post/1540541/


All Articles