Window.open () is blocked by the browser when called with a promise

I have a code like this:

window.open('https://api.instagram.com/oauth/authorize/',
'_blank',
'width=700,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0,modal=yes');

This works great when called from anywhere in the code, but when I use it in a promise (see below), it is always blocked by the browser. Any suggestions?

action().success(function (r) {
  // window.open(...);
}

Promises by angular.

+4
source share
3 answers

The promise is triggered in response to an HTTP response from an Ajax request. This is not a user-initiated event, so pop-ups are blocked. Use the window that the user gives you instead of creating a new one.

+5
source

The solution I use for this problem is

  • ( , )
  • ( win.location)
+9
            var newTab = $window.open('', '_blank');
        promise
            .then(function () {
                var url = '...';
                newTab.location.href = url;
            });
+6
source

Source: https://habr.com/ru/post/1538026/


All Articles