在Phonegap构建应用程序(iOS / Android)中打开外部链接 [英] Open external links in Phonegap Build App (iOS/Android)

查看:325
本文介绍了在Phonegap构建应用程序(iOS / Android)中打开外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Phonegap Build 部署mi应用程式,我使用的是 Cordova 3.3.0 版本。

I'm using Phonegap Build to deploy mi Apps, I'm using the Cordova 3.3.0 version.

我想在本机浏览器中开启外部连结( Android / iOS )。我正在尝试使用Cordova的 InAppBrowser插件,但它不适用于我。打开链接,但在应用程序内无回拨按钮...:/

I want open external links in the native browser (Android/iOS). I'm trying to use the InAppBrowser plugin of Cordova, but it doesn't work for me. Open the links but inside the App without back button... :/

我看到的答案像包括phonegap.js文件(但是当使用Phonegap Build部署时,您不必包括它,PGB为您),或使用或使用函数打开链接+ InAppBrowser插件,甚至谁说这是固定的在本地部署,但我无法部署,因为我的Mac不支持新版本。

I've seen answers like Include phonegap.js file (but when deploys with Phonegap Build you don't have to include it, PGB do it for you), or using or using a function to open links + InAppBrowser Plugin, or even who say that this is fixed deploying locally, but I can't deploy locally because my Mac doesn't support the new versions of XCode and iOS SDK's.

这是我的 config.xml 的相关代码:

<preference name="phonegap-version" value="3.3.0" />
<gap:plugin name="org.apache.cordova.inappbrowser" version="0.3.3" />
<feature name="InAppBrowser">
    <param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
    <param name="ios-package" value="CDVInAppBrowser" />
</feature>
<access origin="*" />

这是 JS函数 >

This is the JS function I've been trying:

function abrirURL(url){
    if(device.platform === 'Android') {
        navigator.app.loadUrl(url, {openExternal:true});
    } else {
        window.open(url, '_system');
    }
}

并且链接尝试,从最基本到使用函数:

And the links I tried, from the most basic to the use of functions:

<a href="http://www.example.com" target="_blank">Link</a>
<a href="#" onClick="abrirURL('http://www.example.com');">Link</a>
<a href="#" onClick="window.open('http://www.example.com', '_blank');">
<a href="#" onClick="window.open('http://www.example.com', '_system');">

没有任何东西对我有用,有人帮助我。感谢!

Nothing of this works for me, somebody help me please. Thanks!

推荐答案

我的问题的解决方案是 include phonegap.js file to my < head> 在我将使用InAppBrowser的所有页面中:< script src =phonegap.js>< / script>

The solution for my problem was include phonegap.js file to my <head> in all the pages where I will use the InAppBrowser: <script src="phonegap.js"></script>

我会解释一下,为什么这个解决方案第一次对我来说似乎不合逻辑(也许你也),但后来我试过,它的工作原理。

I'm gonna explain a little, why this solution in first time doesn't seem logic to me (and maybe you too), but then I tried and it works.

这是他的插件中的Phonegap文档部分说:


如果插件使用 js-module 元素来指示cordova加载插件javascripts,则不需要< script> 引用来加载插件。 cordova插件

"If a plugin utilizes the js-module element to direct cordova to load the plugin javascripts, then no <script> references will be necessary to load a plugin. This is the case for the core cordova plugins"

InAppBrowser 是一个核心cordova插件。但是由于一些奇怪的原因,直到你包括 phonegap.js 文件(至少在0.3.3版本)。

InAppBrowser is a core cordova plugin. But for some strange reason don't work until you include the phonegap.js file (at least in 0.3.3 version).

注意:我发现了一个错误。有些人说你必须包括3个文件: phonegap.js cordova.js cordova_plugins.js 。但是当我包含这3个文件我的应用程序在iOS 7中工作正常,但在iOS 6忽略使用插件(使用:Cordova 3.3.0 + Phonegap Build + InAppBrowser 0.3.3)。

NOTE: I found a bug. Some people says that you have to include 3 files: phonegap.js, cordova.js and cordova_plugins.js. But when I include this 3 files my app works fine in iOS 7, but in iOS 6 ignore the use of the plugin (Using: Cordova 3.3.0 + Phonegap Build + InAppBrowser 0.3.3).

这篇关于在Phonegap构建应用程序(iOS / Android)中打开外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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