InAppBrowser插件科尔多瓦/ PhoneGap的 - 的window.open无法打开,在默认浏览器链接 [英] InAppBrowser plugin for Cordova/Phonegap -- window.open not opening links in default browser

查看:464
本文介绍了InAppBrowser插件科尔多瓦/ PhoneGap的 - 的window.open无法打开,在默认浏览器链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给InApBrowser PhoneGap的插件添加到我的web应用程序,以打开手机默认浏览器的链接。

I'm trying to add the InApBrowser PhoneGap plugin to my web app in order to open the links in the mobile default browser.

web应用程序编程与AngularJS和IonicFramework。

The webapp is programmed with AngularJS and IonicFramework.

我知道有非常类似的问题,但没有我试过的解决方案迄今的工作。

I know there are very similar questions, but none of the solutions I've tried has worked so far.

所以,当我创建的 apk文件的和我的Andr​​oid手机设备上运行它的一些事情没有达到预期效果。顺便说一句,我打造的 apk文件的通过 https://build.phonegap.com/

So when I create the apk file and run it on my Android phone device some things don't work as expected. By the way, I build the apk file through the https://build.phonegap.com/.

在我的指数文件我有这个功能:

In my index file I have this function:

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

我的一个问题是,与这块$ C的$ C

  <p>
    <a id="btn-noticias" class="button button-block button-stable external" 
        ng-href="{{noticia.uri}}">
      Ver noticia en la web
    </a>
  </p>

链接在APPVIEW打开,而不是在默认浏览器。

the link is opened in the appview, not in the default browser.

而在<一个href=\"https://github.com/daniegarcia254/smartculm_test/blob/master/www/templates/examenesSeptiembre.html\"相对=nofollow>这块code 的:

            <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 ......只是不打开链接。

the app doesn't even open the link, not in the browser, no in the appview...just doesn't open the link.

在这里,您可以看到可以的config.xml文件

Here you can see may config.xml file:

<?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 code?

您可以访问我的整个项目这里

You can access to my whole project here.

更新
我发现在的PhoneGap文档的访问标签(也称为白名单)在config.xml

UPDATE I've found the next information in the PhoneGap documentation for the access tag (also known as whitelist) in the config.xml:

在Android上,如果一个域名被列入白名单,一个链接将接管整个web视图。如果不是的话,它会在浏览器中打开。

on Android, if a domain is whitelisted, a link will take over the entire webview. If it is not, it will open in the browser.

所以,按照我的理解,如果我想在默认浏览器打开我的所有链接(的http://秆.unizar.es / *放大器; https://culm.unizar.es/ *)我必须避免它们纳入白名单中。 ¿我怎么做呢?我有点糊涂了......我试过,但如果不知道这样做确定。

So, as I understand it, if I want to open in the default browser all my links (http://culm.unizar.es/* & https://culm.unizar.es/*) I have to avoid including them in the whitelist. ¿How I do that? I'm a little confused...I've tried but not sure if doing it ok.

推荐答案

这是code我用的,因为从这里几个来源编译:

This is the code I use, as compiled from several sources here:

    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只是在检查看看设备==未定义,看看运行的网站(几乎所有我的应用我建立一个网站)。而且,是的,我已经在这个项目还应用程式内浏览器插件。

The "app.isPhoneGap" just checks if device == undefined to see if running as website (almost all my apps I build as a website). And, yes, I have the InApp browser plugin in the project also.

这篇关于InAppBrowser插件科尔多瓦/ PhoneGap的 - 的window.open无法打开,在默认浏览器链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆