[英]window.open() is blocked by browser when is called from promise
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,scrollbars=1,resizable=1,left=0,top=0,modal=yes');
This works fine when is called from any place of code, but when I use it in promise (see below), it is always blocked by browser.这在从任何代码位置调用时都可以正常工作,但是当我在承诺中使用它时(见下文),它总是被浏览器阻止。 Any suggestions?
有什么建议么?
action().success(function (r) {
// window.open(...);
}
Promises are from angular.承诺来自角度。
var newTab = $window.open('', '_blank');
promise
.then(function () {
var url = '...';
newTab.location.href = url;
});
The solution I use to this problem is to我用来解决这个问题的解决方案是
win.location
)win.location
)The promise fires in response to you getting the HTTP response back from the Ajax request.当您从 Ajax 请求中获取 HTTP 响应时,promise 会触发。 That isn't a user triggered event, so popups are blocked.
这不是用户触发的事件,因此会阻止弹出窗口。 Use the window the user gives you instead of creating a new one.
使用用户给你的窗口,而不是创建一个新窗口。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.