Avoid browser popup blockers

后端 未结 9 1921
一个人的身影
一个人的身影 2020-11-22 12:15

I\'m developing an OAuth authentication flow purely in JavaScript and I want to show the user the \"grant access\" window in a popup, but it gets blocked.

How can I

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 12:38

    I didn't want to make the new page unless the callback returned successfully, so I did this to simulate the user click:

    function submitAndRedirect {
      apiCall.then(({ redirect }) => {
          const a = document.createElement('a');
          a.href = redirect;
          a.target = '_blank';
          document.body.appendChild(a);
          a.click();
          document.body.removeChild(a);
      });
    }
    

提交回复
热议问题