<pre><script type=
"text/javascript"
charset=
"utf-8"
>
document.addEventListener(
"deviceready"
, onDeviceReady,
false
);
function
onDeviceReady() {
checkConnection();
document.addEventListener(
"backbutton"
, eventBackButton,
false
);
document.addEventListener(
"menubutton"
, eventMenuButton,
false
);
document.addEventListener(
"searchbutton"
, eventSearchButton,
false
);
}
function
onConfirm(button) {
if
(button ==
'1'
) {
navigator.app.exitApp();
}
else
{
}
}
function
eventBackButton() {
navigator.notification.confirm(
'确定退出cfxxi?'
,
onConfirm,
'退出应用'
,
'确定,取消'
);
}
function
eventMenuButton() {
}
function
eventSearchButton() {
}
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]==
'No network connection'
||
typeof
states[networkState] ==
"undefined"
)
{
Ext.Msg.alert(
'警告'
,
'应用需要连接网络获得数据,请打开网络.'
,
function
(){
navigator.device.exitApp();
});
}
};
</script></pre>