在回调函数中window.open默认是会被拦截的,因为浏览器判断它不是用户自己打开的,存在安全风险,所以可以伪造一个用户点击事件来避开,代码如下:
function newWindow(url, id) { var a = document.createElement('a'); a.setAttribute('href', url); a.setAttribute('target', '_blank');a.setAttribute('id', id); if(!document.getElementById(id)) { document.body.appendChild(a);} a.click();
}
使用时直接将链接传入url就行,id可传可不传。