【问题标题】:cordova open external website in system browser instead in app科尔多瓦在系统浏览器中打开外部网站,而不是在应用程序中
【发布时间】:2016-02-10 10:29:03
【问题描述】:

Cordova 不会在其应用程序中打开外部网站。当它启动时,它将在系统浏览器中打开。 这是我的代码

来源:http://antonylees.blogspot.in/2013/02/launch-website-as-mobile-app-using.html

index.html

<!DOCTYPE html>
<html>
    <head>
        <title>Hello World</title>
        <script type="text/javascript" src="cordova.js"></script>
        <script>

            document.addEventListener("deviceready", onDeviceReady, false); 

            function checkConnection() {
                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';

                return networkState;
            }            

            function onDeviceReady() {
                var networkState = checkConnection();
                alert(networkState);
                if (networkState == Connection.NONE) {
                    navigator.notification.alert('This app requires an internet connection'); 
                } else {
                    window.location="http://www.google.co.in";
                }
            }

        </script>
    </head>
    <body>

    </body>
</html>

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Dola</name>
    <description>
        Dola
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Dola Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" version="1" />
    <access origin="http://www.google.co.in" />
    <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>

</widget>

我搜索了所有的文档,但仍然无法找出问题所在。请帮帮我。

【问题讨论】:

  • 使用inAppBrowser插件打开外部网站
  • @Rudrakshya,你的问题解决了吗?
  • 没有还没有解决。我添加了应用浏览器。但它有网址栏。我不想要那个。我希望我的应用程序中的网站看起来像原生网站。

标签: android cordova


【解决方案1】:

最简单的方法是在config.xml 中编辑您的src 标记以指向您的外部网站。这不需要安装 InAppBrowser Plugin 内容src="http://example.com"

否则安装 InAppBrowser 并以以下方式加载您的外部网站以避免工具栏或缩放功能。

var ref = window.open('https://example.com/', '_blank', 'location=no,toolbar=no,zoom=no');

【讨论】:

  • 编辑 config.xml 中的 src 标签对我不起作用。该网站仍会在系统浏览器中打开。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-14
  • 1970-01-01
  • 2016-12-29
  • 2016-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多