我正在尝试将InApBrowser PhoneGap插件添加到我的网络应用中,以便在移动默认浏览器中打开链接。
使用AngularJS和IonicFramework对webapp进行编程。
我知道有非常相似的问题,但到目前为止,我尝试过的解决方案都没有。
因此,当我创建 apk文件并在我的Android手机设备上运行时,有些东西无法按预期工作。顺便说一下,我通过https://build.phonegap.com/构建 apk文件。
在我的index文件中,我有这个功能:
<!-- JQuery library -->
<script src="lib/jquery-2.1.3.min.js"></script>
<script type="text/javascript">
$(document).on('click', '.external', function (e) {
e.preventDefault();
window.open(e.target.href, '_system');
});
</script>
我的一个问题是使用this piece of code:
<p>
<a id="btn-noticias" class="button button-block button-stable external"
ng-href="{{noticia.uri}}">
Ver noticia en la web
</a>
</p>
链接在appview中打开,而不是在默认浏览器中打开。
<a class="item lista-item examen external" ng-repeat="examen in filteredExSept"
ng-href="{{examen.URI}}"
ng-hide="errorConexionExSept || examenesSeptiembre.length==0 || filteredExSept.length==0">
<div class="tituloExamen" ng-bind-html="examen.asignatura"></div>
</a>
该应用甚至没有打开链接,不在浏览器中,在appview中没有...只是没有打开链接。
在这里你可以看到config.xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<widget id="com.ionicframework.myapp377389"
version="0.0.1"
xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:gap="http://phonegap.com/ns/1.0">
<name>SmartCULM</name>
<description>
An application...
</description>
<author email="gps_e25@googlegroups.com">
Daniel García Páez
</author>
<content src="index.html"/>
<access origin="*"/>
<!--
If you do not want any permissions to be added to your app, add the
following tag to your config.xml; you will still have the INTERNET
permission on your app, which PhoneGap requires.
-->
<preference name="permissions" value="none"/>
<!-- Core plugins -->
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="org.apache.cordova.device" />
<!-- Define app icon for each platform. -->
<icon src="img/apk_icon.png" />
</widget>
所以,任何人都知道我做错了什么?使用InAppBrowser插件还是使用angularjs代码?
您可以访问我的整个项目here。
更新 我在config.xml中的PhoneGap documentation中找到了访问标记(也称为白名单)的下一个信息:
在Android上,如果某个域列入白名单,则链接将接管整个网页浏览。如果不是,它将在浏览器中打开。
所以,据我所知,如果我想在默认浏览器中打开我的所有链接(http://culm.unizar.es/ *&amp; https://culm.unizar.es/ *),我必须避免将它们包含在白名单中。 ¿我是怎么做到的?我有点困惑......我已经尝试但不确定是否可以。
答案 0 :(得分:2)
这是我使用的代码,由以下几个来源编译:
var externalLinkToOpen = $(this).attr("href");
if (app.isPhoneGap()) {
if (device.platform === 'Android') {
navigator.app.loadUrl(externalLinkToOpen, { openExternal: true });
} else {
window.open(externalLinkToOpen, '_system');
}
} else {
window.open(externalLinkToOpen, "_blank");
}
“app.isPhoneGap”只是检查设备是否= = undefined以查看是否作为网站运行(几乎所有我构建的网站都是我的应用程序)。而且,是的,我在项目中也有InApp浏览器插件。
答案 1 :(得分:1)
在config.xml中:
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
请更新是否有效&lt;我和android
有同样的问题