I have created a Phonegap Android app which shows a welcome page then opens a ChildBrowser window. I want my app to close when the user clicks the "exit" button of the ChildBrowser. I am binding the onClose
event to a function, but it gives a call to that function just after it loads, so I am not able to see the ChildBrowser window. It exits before that.
Below is my code:
<script>
var cb = new ChildBrowser();
cb.onClose = onCloseBrowser();
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
try {
cb.showWebPage('http://www.google.com/',{ showLocationBar: true });
}catch (err){
console.log(err);
}
}
function onCloseBrowser() {
//alert("I am here");
navigator.app.exitApp();
}
</script>
You need to omit the () when you set your cb.onClose handler. If you don't the method will be executed immediately. So do:
cb.onClose = onCloseBrowser;