解决异步加载window.open 被拦截
原因:在chrome的安全机制里面,非用户粗发的window.open方法,是会被拦截的
当发送完ajax之后window.open就会被拦截;原因是用户没有直接发出window.open,而是发出一个ajax请。求,会被浏览器误认为是什么垃圾广告之类的拦截;
解决方法:
1.把打开窗口的操作写在onclick事件中
$('#btn').click(function() {
//不会被拦截
window.open(url)
});
2.更换打开方式(推荐)
window.open(url) => window.location.href=url
3.先打开新窗口
$('#btn').click(function () {
//打开一个不被拦截的新窗口
var newWindow = window.open();//H5的话 window.open('','_self')
$.ajax({
url: 'xxxx.com',
success: function (url) {
//修改新窗口的url
newWindow.location.href = url;
}
})
});//先在回调函数之前打开新窗口,后再加载url