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