In phonegap application there are many events that can be used and for these events the application code may add a listeners.
Lets take an example to evaluate this thing:
HTML:
<html>
<head>
<title>Events Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
</head>
<body onload="onLoad()">
</body>
</html>
JS:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
document.addEventListener("menubutton", onMenuKeyDown, false);
}
function onPause() {
// this will fire pause event
}
function onResume() {
// this will fire resume event
}
function onMenuKeyDown() {
// this will fire menubutton event
}
Please note that you can use document.addEventListener in your application once the deviceready.
Here is the list of events:
- deviceready
- pause
- resume
- backbutton
- menubutton
- searchbutton
- startcallbutton
- endcallbutton
- volumedownbutton
- volumeupbutton
Also the device ready event fire only when cordova is loaded.
document.addEventListener("deviceready", onDeviceReady, false);
Hope this blog makes you clear about the events in phonegap.
0 Comment(s)