简体   繁体   English

远程加载Cordova / PhoneGap应用程序

[英]Remotely Loading an Cordova/PhoneGap App

In regards to Cordova 3.4: 关于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. 我在互联网上遇到了关于使用cordova / phonegap远程加载网页的各种帖子,我无法让它工作。 I have read questions #28 and #29 on github and various other posts. 我在github和其他各种帖子上读过#28#29的问题。

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). 我通过config.xml中的内容设置直接加载url(下面的示例是在我的本地开发机器上,但无论我在公司防火墙中使用哪个URL都无关紧要)。 I have also tried doing a window.location to the url, but that doesn't work either. 我也试过对URL进行window.location,但这也不起作用。

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

The page loads fine except for the deviceready event doesn't fire. 页面加载正常,但deviceready事件不会触发。 The www files local to the cordova app works, just nothing remote. cordova应用程序本地的www文件可以工作,只是没有远程。

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! 谢谢!

Don't wait for onload to fire before adding the deviceready event listener. 在添加deviceready事件侦听器之前,不要等待onload触发。 I suspect deviceready has already fired and therefore you're not getting your handler called. 我怀疑deviceready已经被解雇了,因此你没有调用你的处理程序。 Even if cordova isn't loaded it contains logic to fire even for listeners registered before it was loaded. 即使未加载cordova,它也包含即使对于在加载之前注册的侦听器也要触发的逻辑。

Also, cordova will add script tags to load its own dependencies so you should only need to include the cordova.js script tag. 此外,cordova将添加脚本标记以加载其自己的依赖项,因此您只需要包含cordova.js脚本标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM