window.open popup getting blocked during click event

前端 未结 5 2030
刺人心
刺人心 2020-11-30 07:30

What I ultimately need to do is run an $.ajax() call and then after that is run, open a new window.

A use clicks on a \"Preview\" button that saves thei

5条回答
  •  隐瞒了意图╮
    2020-11-30 08:11

    I solved my case by making the Ajax call synchronous. E.g. (with jQuery):

    $("form").submit(function(e){
        e.preventDefault();
        $.ajax({
          async: false,
          url: ...,
          data: ...,
          success: function(results){
              if(results.valid){
                  window.open(...);
              }
          }
        });
        return false;
      });
    

提交回复
热议问题