window.open() is blocked by browser when is called from promise

前端 未结 3 1993
灰色年华
灰色年华 2020-12-19 05:22

I have code like this:

window.open(\'https://api.instagram.com/oauth/authorize/\',
\'_blank\',
\'width=700,height=500,toolbar=0,menubar=0,location=0,status=1         


        
相关标签:
3条回答
  • 2020-12-19 05:58
                var newTab = $window.open('', '_blank');
            promise
                .then(function () {
                    var url = '...';
                    newTab.location.href = url;
                });
    
    0 讨论(0)
  • 2020-12-19 06:03

    The promise fires in response to you getting the HTTP response back from the Ajax request. That isn't a user triggered event, so popups are blocked. Use the window the user gives you instead of creating a new one.

    0 讨论(0)
  • 2020-12-19 06:17

    The solution I use to this problem is to

    1. immediately open the window and keep a reference (when it's legal, that is in the event handler)
    2. launch the asynchronous operation
    3. then, in the promise, use the window you opened and fill it (you may use win.location)
    0 讨论(0)
提交回复
热议问题