Chrome dismisses confirm() promps immediately without any user interaction

僤鯓⒐⒋嵵緔 提交于 2019-12-01 05:20:26

I had exactly same issue. It seems like a chrome issue.

It requires a trick. In my case, it worked by putting 0.1 sec delay with setTimeout function.

Try this. It will work.

function doConfirm() {
  var c = confirm('Are you sure you wish to delete this entry?');
  if (c) {
    $.ajax(
        '/api/show/competition/delete',
        {
            'method': 'POST',
            'data': { 'id' : 9 },
            'dataType': 'json',
            'complete': function(response, status) {
                if (response.responseJSON.error) {
                    alert(response.responseJSON.message);
                    window.location.reload();
                } else {
                    document.location.href = "/show/application/competition";
                }
            }
        }
    );
  } else {
    document.location.href = "/show/application/competition/entry/9";
  }
}

$(document).ready(function() {
  setTimeout(function(){ doConfirm() }, 100);    
});

In my case, the problem was caused by an iframe. I had a youtube video iframe, and the alert would close few milliseconds after showing. After removing the iframe, everything worked fine again.

In my case, the Facebook Remarketing Pixel was the source of the problem.

In my case the issue was appearing for confirm dialog in click event function. Replacing "click" by "mouseup" resolved the issue.

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