其他分享
首页 > 其他分享> > android-PhoneGap框架中navigator.notification.confirm中的按钮顺序

android-PhoneGap框架中navigator.notification.confirm中的按钮顺序

作者:互联网

我在PhoneGap应用中使用以下代码.

        function registrationCallBack(button){
            if(button == 2) {
                window.location.href = "login.html";
            }
        }

   navigator.notification.confirm("Are you sure ?", registrationCallBack, "Confirmation", "Cancel, Ok");

在iPhone中,按钮的顺序正确显示为“取消”和“确定”.
  但是对于Android,按钮的顺序相反.依次为“确定”和“取消”.

结果,在回调方法中按钮索引被更改了.

欢迎所有建议:)

谢谢,

解决方法:

尝试使用以下解决方案:

function showConfirm(message, callback, buttonLabels, title){

    //Set default values if not specified by the user.
    buttonLabels = buttonLabels || 'OK,Cancel';

    title = title || "default title";

    //Use Cordova version of the confirm box if possible.
    if(navigator.notification && navigator.notification.confirm){

            var _callback = function(index){
                if(callback){
                    callback(index == 1);
                }
            };

            navigator.notification.confirm(
                message,      // message
                _callback,    // callback
                title,        // title
                buttonLabels  // buttonName
            );

    //Default to the usual JS confirm method.
    }else{
        invoke(callback, confirm(message));
    }
}

这是您将如何使用它:

var message = "Would you like to proceed?";
var title = "Important Question";

//The first element of this list is the label for positive 
//confirmation i.e. Yes, OK, Proceed.
var buttonLabels = "Yes,No";

var callback = function(yes){
    if(yes){
        alert('Proceed');
    }else{
        alert('Do Not Proceed'); 
    }
};

showConfirm(message, callback, buttonLabels, title);

标签:cordova,phonegap-plugins,iphone,android
来源: https://codeday.me/bug/20191101/1984414.html