当浏览器检测到非用户操作(即非click等事件)跳转页面或弹出新窗口时会被有些浏览器拦截;
解决办法:
- 当只需在本页面跳转时使用window.location.href = ‘url’ 代替 window.open(‘url’); window.location仅支持本站地址的跳转;
- 使用a标签代替(不适合放在ajax请求的回调函数中)
function newOpenWin(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.appendShild(a);
a.click();
}
}
3.先弹出窗口,然后进行重定向