如何使用cordova inappbrowser插件

时间:2017-08-17 23:43:02

标签: cordova ionic-framework hybrid-mobile-app inappbrowser

我正在使用apache cordova开发移动应用程序。这是一个非常简单的应用程序,加载响应式网站。目前,我使用HTML标记加载页面,但我想将Cordova inappbrower用于此目的。

这是我的www / index.html文件:

<!DOCTYPE html>

<html>
    <head>
        <title>Title</title>
    </head>
    <body style="width: 100%;height: 100%;overflow: hidden;">
    <iframe style="width: 100%;height: 100%; border: none;" height="100%" src="http://www.mywebsite.com/"></iframe>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

这是我的www / js / index.js文件:

var app = {

    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    onDeviceReady: function() {

      var networkState = navigator.network.connection.type;

            var states = {};
            states[Connection.UNKNOWN]  = 'Unknown connection';
            states[Connection.ETHERNET] = 'Ethernet connection';
            states[Connection.WIFI]     = 'WiFi connection';
            states[Connection.CELL_2G]  = 'Cell 2G connection';
            states[Connection.CELL_3G]  = 'Cell 3G connection';
            states[Connection.CELL_4G]  = 'Cell 4G connection';
            states[Connection.NONE]     = 'No network connection';

            if ((states[networkState]) == states[Connection.NONE])
            {
            window.location.href="noconnection.html"; 
            } else {
            this.receivedEvent('deviceready');
            }
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

请帮助。我已经安装了inappbrowser但我不知道如何使用它。

1 个答案:

答案 0 :(得分:0)

结帐此链接:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-inappbrowser/

要进行快速测试,您可以尝试

window.open("http://www.mywebsite.com/", "_blank");