4

In regards to Cordova 3.4:

I have come across various posts on the internets about doing a remote load of a webpage with cordova/phonegap and I have not been able to get it to work. I have read questions #28 and #29 on github and various other posts.

I am loading the url directly via the content setting in config.xml (the below example is on my local dev machine, but doesn't matter which url I use within our corporate firewall). I have also tried doing a window.location to the url, but that doesn't work either.

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

The page loads fine except for the deviceready event doesn't fire. The www files local to the cordova app works, just nothing remote.

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>

Thanks!

Jason Cochran
  • 316
  • 3
  • 10
  • For me, the device ready fires, but window.plugins is undefined in services.js still when calling, e.g. PushNotification.initialize. I've tested on Android but not yet on iOS. Using Cordova 4.0.0 / Ionic 1.2.8 – mylord Nov 11 '14 at 15:37
  • Hello Jason, any luck with getting this to work. Please take a look at: http://stackoverflow.com/questions/26893007/how-to-load-a-remote-javascript-app-into-a-cordova-windows-phone-8-1-app-and-hav – paul Nov 12 '14 at 17:35
  • We decided to go with using local assets that are imported from a rails project using a grunt task. – Jason Cochran Nov 13 '14 at 19:21

1 Answers1

0

Don't wait for onload to fire before adding the deviceready event listener. I suspect deviceready has already fired and therefore you're not getting your handler called. Even if cordova isn't loaded it contains logic to fire even for listeners registered before it was loaded.

Also, cordova will add script tags to load its own dependencies so you should only need to include the cordova.js script tag.

Chris A
  • 368
  • 1
  • 8
  • AFAIK, Cordova will trigger the document ready event, even if you add the event listener **after** the event is originally triggered – feupeu Nov 13 '17 at 14:48