PhoneGap:InAppBrowser

时间:2015-11-06 20:50:32

标签: android html cordova

我已经安装了插件: https://github.com/apache/cordova-plugin-inappbrowser 我按照他们的安装说明进行了操作:

Installation

cordova plugin add cordova-plugin-inappbrowser
If you want all page loads in your app to go through the InAppBrowser, 
you can simply hook window.open during initialization. For example:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.open = cordova.InAppBrowser.open;
}

我已将此添加到我的config.xml中:

<gap:plugin name="cordova-plugin-inappbrowser" source="npm" version="1.0.1" />
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>

这是我使用上述代码的代码:

    <a href="javascript:testOne();">Test 1</a>
    <br>
    <a href="javascript:testTwo();">Test 2</a>

<script type="text/javascript">
function testOne() {
    var ref = cordova.InAppBrowser.open('http://google.com', '_blank', 'location=yes');
}
function testTwo() {
    var ref = cordova.InAppBrowser.open('http://google.com', '_system', 'location=yes');
}
</script>

无效,当我点击这些链接(在Android上)时,没有任何反应。为什么呢?

1 个答案:

答案 0 :(得分:0)

你试过吗

window.open(‘http://example.com’, ‘_blank’);

没有您添加的文档就绪监听器。