最近项目用到window.open(),打开新页面 有时候会被拦截?
- 直接手动触发不会被拦截;
- 间接触发会被拦截;原因:=》浏览器检测到非用户操作产生的新弹出窗口,会对其进行阻止。因为浏览器认为这是一个广告。window.open()放在ajax的回调函数中执行会导致被拦截。
解决方案:
手动触发handleManage,直接通过window.open()打开空白页面,赋值loading状态,接口返回成功后更换href。
import Loading from './loading.js'; // 手动编写loading样式,导出字符串;
handleManage(item) {
var newWin = window.open('about:blank');
newWin.document.body.innerHTML = Loading;
getUrlService(item.id).then(({ data: result }) => {
if (result.success) {
newWin.location.href = result.data;
}
});
},