Avoid browser popup blockers

后端 未结 9 1997
一个人的身影
一个人的身影 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:39

    In addition Swiss Mister post, in my case the window.open was launched inside a promise, which turned the popup blocker on, my solution was: in angular:

    $scope.gotClick = function(){
    
      var myNewTab = browserService.openNewTab();
      someService.getUrl().then(
        function(res){
            browserService.updateTabLocation(res.url, myNewTab);
    
        }
      );
    };
    

    browserService:

    this.openNewTab = function(){
         var newTabWindow = $window.open();
         return newTabWindow;
    }
    
    this.updateTabLocation = function(tabLocation, tab) {
         if(!tabLocation){
           tab.close();
         }
         tab.location.href = tabLocation;
    }
    

    this is how you can open a new tab using the promise response and not invoking the popup blocker.

提交回复
热议问题