Phonegap-从外部网站访问api [英] Phonegap - access to api from external website
问题描述
我在配置文件中设置了
<access origin="*" subdomains="true" />
<access origin=".*" subdomains="true" />
<content src="http://mydomain.pl/aps_mobile/" />
但是在 http://mydomain.pl/aps_mobile/上,不要执行事件"deviceready",并且navigator.camera未定义. 我做错了什么?
如果从外部主机执行cordova脚本,则无法访问硬件资源,因为该脚本未映射到Phonegap的libs/cordova.xxxjar应用. 但是您可以通过以下方式解决:
在res/xml/config.xml中
<access origin="*" />
<content src="index.html" />
在assets/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.
希望对您有帮助
I set in config files:
<access origin="*" subdomains="true" />
<access origin=".*" subdomains="true" />
<content src="http://mydomain.pl/aps_mobile/" />
But on http://mydomain.pl/aps_mobile/ don't execute event "deviceready" and navigator.camera is undefined. What i doing wrong?
You don't access to hardware resource if you execute the cordova script from a external host because the script is not mapped to libs/cordova.x.x.x.jar of Phonegap application. But you can resolve in this way:
in res/xml/config.xml
<access origin="*" />
<content src="index.html" />
in assets/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>
finaly, in camera configuration, you must set destinationType to 0 if you wanto DATA_URL, 1 if you want FILE_URI or 2 if you want NATIVE_URI.
I hope to help you
这篇关于Phonegap-从外部网站访问api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!