2014-03-31 81 views
1

我创建了一个提醒按钮,用于在我的应用程序中使用后退按钮。Phonegap:后退按钮不起作用

这里是我做了什么

document.addEventListener("deviceready", onDeviceReady, false); 

function onDeviceReady() { 
    document.addEventListener("backbutton", onBackKeyDown, false); //Listen to the User clicking on the back button 
} 

function onBackKeyDown(e) { 
    e.preventDefault(); 
    navigator.notification.confirm("Are you sure you want to return to Menu ?", onConfirm, "Confirmation", "Yes,No"); 
    // Prompt the user with the choice 
} 

function onConfirm(button) { 
    if(button==2){//If User selected No, then we just do nothing 
     return; 
    }else{ 
     window.location.replace("Menu.html"); 
    } 
} 

但问题是,当我用我的手机上的返回按钮,第一次它显示了警报,但单击后退按钮两次当它同像后退按钮一样。它回到上一页,而不是停留在当前页面上。警告框上的按钮(是或否)完美地工作。

我想删除两次单击后退按钮并保持在同一页面上的警报。我怎样才能做到这一点 ?

回答

0

您是否包含以下js & css?

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" /> 
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script> 
<script type="text/javascript" src="cordova.js"></script> 
+0

是的,我做到了。这就是为什么警报按钮返回按钮工作。 – insanity