Cordova / Phonegap backbutton处理程序无法正常工作

时间:2012-11-17 01:25:56

标签: jquery-mobile cordova android-4.0-ice-cream-sandwich back-button

我正在使用Phonegap和jQuery Mobile。这是我的代码:

function onDeviceReady() {
  // Register the event listener
  document.addEventListener("backbutton", onBackKeyDown, false);
  setPage();
}
function setPage(){
  //All pages at least 100% of viewport height
  var viewPortHeight = $(window).height();
  //alert(viewPortHeight );
  var headerHeight = $('div[data-role="header"]').height();
  var footerHeight = $('div[data-role="footer"]').height();
  var contentHeight = viewPortHeight - headerHeight - footerHeight-120;
  // Set all pages with class="page-content" to be at least contentHeight
  $('div[class="page-content"]').css({'min-height': contentHeight + 'px'});
}
function confirmExit(){
  alert("exit...");
}
// Call onDeviceReady when Cordova is loaded.
// At this point, the document has loaded but cordova-2.2.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() { alert("onload");
  document.addEventListener("deviceready", onDeviceReady, false);
}
// Handle the back button
function onBackKeyDown() {
  alert("onbackkeydown");
  console.log("back clicked");
  confirmExit();
}
$(document).ready(function(){});

在身体标签中:

<body onload="onLoad();">

但是当我加载应用时,我只会在onLoad方法中收到提醒。

我做错了什么?

非常感谢。

0 个答案:

没有答案
相关问题