window.open() 在从 promise 调用时被浏览器阻止 [英] window.open() is blocked by browser when is called from promise
本文介绍了window.open() 在从 promise 调用时被浏览器阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的代码:
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 来自 angular.
Promises are from angular.
推荐答案
当您从 Ajax 请求中获得 HTTP 响应时,承诺会触发.这不是用户触发的事件,因此会阻止弹出窗口.使用用户给你的窗口,而不是创建一个新窗口.
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.
这篇关于window.open() 在从 promise 调用时被浏览器阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文