/ / function onDeviceReady index.js -
Phone Gap / Cordova
events native JS
:
document.addEventListener("deviceready", onDeviceReady, false);
/
:
function onDeviceReady()
/ native
:
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="cordova.js"></script>
: cordova.js <script> .
index.html
index.html index.js
:
:
<!DOCTYPE html>
<html>
<head>
<title>Events</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("online", onOnline, false);
document.addEventListener("offline", onOffline, false);
document.addEventListener("backbutton", onBackKeyDown, false);
window.addEventListener("batterycritical", onBatteryCritical, false);
window.addEventListener("batterylow", onBatteryLow, false);
window.addEventListener("batterystatus", onBatteryStatus, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
document.addEventListener("searchbutton", onSearchKeyDown, false);
document.addEventListener("startcallbutton", onStartCallKeyDown, false);
document.addEventListener("endcallbutton", onEndCallKeyDown, false);
document.addEventListener("volumedownbutton", onVolumeDownKeyDown, false);
document.addEventListener("volumeupbutton", onVolumeUpKeyDown, false);
}
function onPause() {
alert("Application Pause");
}
function onResume() {
alert("Application Resume");
}
function onOnline() {
alert("Application Online");
}
function onOffline() {
alert("Application Offline");
}
function onBackKeyDown() {
alert("Application BackKeyDown");
}
function onBatteryCritical(info) {
alert("Battery Level Critical " + info.level + "%\nRecharge Soon!");
}
function onBatteryLow(info) {
alert("Battery Level Low " + info.level + "%");
}
function onBatteryStatus(info) {
alert("Level: " + info.level + " isPlugged: " + info.isPlugged);
}
function onMenuKeyDown() {
alert("Application MenuKeyDown");
}
function onSearchKeyDown() {
alert("Application SearchKeyDown");
}
function onStartCallKeyDown() {
alert("Application StartCallKeyDown");
}
function onEndCallKeyDown() {
alert("Application EndCallKeyDown");
}
function onVolumeDownKeyDown() {
alert("VolumeDownKeyDown");
}
function onVolumeUpKeyDown() {
alert("VolumeUpKeyDown");
}
</script>
</head>
<body>
</body>
</html>
/ Functions
,
.
function onDeviceReady()
function onPause()
function onResume()
function onOnline()
function onOffline()
function onBackKeyDown()
function onBatteryCritical(info)
function onBatteryLow(info)
function onBatteryStatus(info)
function onMenuKeyDown()
function onSearchKeyDown()
function onStartCallKeyDown()
function onEndCallKeyDown()
function onVolumeDownKeyDown()
function onVolumeUpKeyDown()