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>
我四处搜索,所有文档,但仍然无法找出问题。请帮帮我。
答案 0 :(得分:0)
最简单的方法是修改src
中的config.xml
代码,指向您的外部网站。这不需要安装InAppBrowser插件
内容src="http://example.com"
否则安装InAppBrowser并以下面的方式加载外部网站,以避免工具栏或缩放功能。
var ref = window.open('https://example.com/', '_blank', 'location=no,toolbar=no,zoom=no');