window.open()弹窗被浏览器拦截

7次阅读

共计 305 个字符,预计需要花费 1 分钟才能阅读完成。

什么情况下会弹窗被拦截
obj.onclick = function(){
window.open(url) // 会被拦截
}

obj.onclick = function () {
ajax({
url: ‘/xxxxxx/’,
success: function (url) {
window.open(url); // 会被拦截
}
})
}
});
解决

obj.onclick = function () {
var newWindow = window.open(); // 先在回调函数之前打开新窗口,后再加载 url
ajax({
url: ‘/xxxxxx/’,
success: function (url) {
newWindow.location.href = url;
}
})
}

正文完
 0