JavaScript confirmation window always returning false on Safari for iPhone

跟風遠走 提交于 2019-12-24 22:27:30

问题


I'm using Knockout.JS to power a form and I have a button that when pressed displays a confirmation window. Only on Safari for iPhone it always returns false. It works with Chrome on my iPhone, and on my iPad and laptop it works on all browsers(including Safari). There are no errors either.

self.submitPayment = function(){
    var errors2 = ko.validation.group(secondValidationGroup);
    if (errors2().length == 0) {
        if(confirm_reservation() == true){
            finalizePayment(); //calls function which displays a new div
        }
        else{
            alert('False was returned'); //displays before I even make a selection
        }
    }
    else{
        errors2.showAllMessages();
    }
}

 //used to confirm submission for submitPayment 
function confirm_reservation(){
    var conf = confirm('Click OK to submit your payment');
    return conf;
}

Before I even make a selection, I get the 'False was returned' alert. So basically it's not even letting me make a selection before it returns the value.

edit - It is now working and I think I may have encountered a bug

I cleared my cookies/cache on my phone and restarted it and then it proceeded to work properly.


回答1:


You may try:

if(confirm('Your question')) 
{ 
 // do things if OK
}
else
{
// do things if KO
}



回答2:


After AOZ suggested that it may have been a bug, I cleared my cookies/cache and restarted my phone and then it proceeded to work. I am using my original method and it now works properly.




回答3:


I think the problem due the asycnhronus things, your "confirm_reservation" method doesnot wait the confirm result, and return false directly.. Can you try below confirm block changing with yours.

confirm('Click OK to submit your payment', function(result) {
  if(result) {
    finalizePayment();
  } else {
    alert('False was returned'); //displays before I even make a selection
  }    
});


来源:https://stackoverflow.com/questions/20871356/javascript-confirmation-window-always-returning-false-on-safari-for-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!