1

我创建了一个 Phonegap Android 应用程序,它显示一个欢迎页面,然后打开一个 ChildBrowser 窗口。当用户单击 ChildBrowser 的“退出”按钮时,我希望我的应用程序关闭。我将onClose事件绑定到一个函数,但它在加载后立即调用该函数,因此我无法看到 ChildBrowser 窗口。它在此之前退出。下面是我的代码:

<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>
4

1 回答 1

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;
于 2012-06-30T22:11:24.760 回答