【问题标题】:Phonegap - access to api from external websitePhonegap - 从外部网站访问 api
【发布时间】:2013-04-17 15:28:52
【问题描述】:
我在配置文件中设置:
<access origin="*" subdomains="true" />
<access origin=".*" subdomains="true" />
<content src="http://mydomain.pl/aps_mobile/" />
但是在http://mydomain.pl/aps_mobile/ 上不要执行事件“deviceready”并且 navigator.camera 是未定义的。
我做错了什么?
【问题讨论】:
标签:
android
cordova
webview
phonegap-build
【解决方案1】:
如果您从外部主机执行cordova 脚本,您将无法访问硬件资源,因为该脚本未映射到Phonegap 应用程序的libs/cordova.x.x.x.jar。
但是你可以这样解决:
在 res/xml/config.xml 中
<access origin="*" />
<content src="index.html" />
在资产/www/index.html
<body>
<script type="text/javascript" src="cordova-x.x.x.js"></script>
<iframe name="framewrap" id="framewrap"
style="border:0;position: absolute; top: 0; left: 0;width: 100%;"
src="http://yourwebsite.pl">
</iframe>
<script type="text/javascript">
document.getElementById("framewrap").contentWindow.navigator = navigator;
</script>
</body>
最后,在相机配置中,如果你想要 DATA_URL,你必须将 destinationType 设置为 0,如果你想要 FILE_URI,你必须设置为 1,如果你想要 NATIVE_URI,你必须设置 2。
希望能帮到你
【解决方案2】:
索引文件不应该在服务器上。您需要在应用程序的资产文件夹中有一个 index.html,并通过 jquery ajax 调用连接到服务器。
还要确保您在 index.html 中导入了 cordova 和 phonegap javascript 文件