如何在phonegap项目中使用(inAppBrowser)插件?

时间:2018-10-23 13:07:03

标签: javascript cordova phonegap-plugins phonegap

我通过以下命令行在我的phonegap项目中安装“ inAppBrowser”插件:

cordova plugin add cordova-plugin-inappbrowser

以及在index.html中写成的打击代码:

<a id="eghdamat_ghabl" href="#" onclick="window.open('http://apache.org', '_blank', 'location=yes'); return false;">click me</a>

,但不会打开链接
config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloWorld</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-inappbrowser" spec="^3.0.0" />
	
	<icon src="icon.png" />
	<splash src="splash.png" />
</widget>

1 个答案:

答案 0 :(得分:0)

您必须在config.xml上添加此行,以允许导航到外部URL

<allow-navigation href="*" />

这将允许导航到任何外部URL。

如果您只想允许导航到apache,则添加此行

<allow-navigation href="https://apache.org" />