如果使用doucment.write()来写入数据Edge会提示下侧问题,谷歌火狐测试无影响!
const iframe = document.createElement('iframe');
let doc = null;
//添加属性
iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
//插入
document.body.appendChild(iframe)
doc = iframe.contentWindow.document;
//创建div标签 插入到iframe中
//处理使用document.write()产出的浏览器提示避免使用的问题
const conDiv = document.createElement('div');
conDiv.innerHTML = res['data']
doc.body.appendChild(conDiv)
//关闭open()方法打开的文档流。
doc.close();
// 获取iframe的焦点,从iframe开始打印
iframe.contentWindow.focus();
//打印
iframe.contentWindow.print();
setTimeout(()=>{
document.body.removeChild(iframe);
},10000)