需求:接收后端图片字符串(Base64编码)转成图片,并在新窗口展示
/**
* @param imgStr 图片base64字符串
* @param imgName 图片名称
**/
function showPic(imgStr, imgName){
// 创建img标签
let img = document.createElement('img');
img.setAttribute( 'src', 'data:image/' +
imgName +
';base64,' + imgStr
);
// 在新窗口打开
let newWindow = window.open(); // 注意:短时间内重复调用会被浏览器拦截
newWindow .document.write(img.outerHTML);
}