1
我想要一个表单在没有互联网连接时返回false。我有脚本,检查页面加载时的互联网连接,它工作正常。但是,当用户提交并且没有互联网时,它会显示警报权限,但仍会尝试提交,并会显示默认错误网页“无法找到该页面”。当没有互联网连接时返回False
<form action="http://usersite.com/script.php" method="post" name="form1" target="_parent" id="form1" onsubmit="checkConnection()">
检查Internet
<script type="text/javascript" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
checkConnection();
}
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';
if ((states[networkState]) == states[Connection.NONE])
alert('No Internet Connection');
return false;
}
</script>
参考这一点,它可以帮助你: [http://stackoverflow.com/questions/28465524/phonegap-no-internet-alert-弹出发出] [1] [1]:http://stackoverflow.com/questions/28465524/phonegap-no-internet-alert-pop-up-issue – Amar1989 2015-02-12 08:29:15