简体   繁体   English

Phonegap:后退按钮不起作用

[英]Phonegap : Back button not working

I have created an alert to back button used in my application. 我创建了一个警报,用于我的应用程序中的后退按钮。

Here is what i have done 这是我所做的

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");
    }
}

But the problem is , when i am using the back button on my phone for the first time it shows the alert but when clicking back button twice it does the same thing as back button does. 但是问题是,当我第一次使用手机上的后退按钮时,它会显示警报,但是当我两次单击后退按钮时,它会执行与后退按钮相同的操作。 It goes back to previous page rather than staying on the current page. 它返回上一页而不是停留在当前页面上。 Both the buttons(yes or no) on alert box works perfectly. 警报框上的两个按钮(是或否)都可以正常工作。

I want to remove the alert on clicking the back button twice and stay on the same page . 我要删除单击两次后退按钮的警报,并停留在同一页面上。 How can i do this ? 我怎样才能做到这一点 ?

Have u included following js & css? 您是否包括以下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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM