1

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>
dda
  • 6,030
  • 2
  • 25
  • 34
www.amitpatil.me
  • 3,001
  • 5
  • 43
  • 61

1 Answers1

4

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;
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Removing braces didnt worked :( but code example provided on your blog worked perfect. http://simonmacdonald.blogspot.in/2011/09/phonegap-android-childbrowser-revamp.html Thanks. Below is the code worked for me window.plugins.childBrowser.onLocationChange = locationChanged; window.plugins.childBrowser.onClose = closed; window.plugins.childBrowser.showWebPage( "http://www.phonegap.com", { showLocationBar: true }); – www.amitpatil.me Jul 02 '12 at 07:07