100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > js打印照片或网页内容

js打印照片或网页内容

时间:2024-07-27 21:12:52

相关推荐

js打印照片或网页内容

printPic(event,item){//点击按钮回调函数//方式1://保存原先网页内容// let bdhtml=window.document.body.innerHTML; // window.document.body.innerHTML=`<img style="width:80%;height:80%;" src="http://localhost:8080/api/msg/pic/${item.bureauId}/${item.code}.jpg">`;// //把需要打印的指定内容赋给body.innerHTML// window.print(); //调用浏览器的打印功能打印指定区域// window.document.body.innerHTML=bdhtml;//重新给页面内容赋值;//window.location.reload();//刷新当前窗口,否则页面其他事件失效//方式2:const printHTML = `<img style="width:90%;height:100%;" src="http://localhost:8080/api/msg/pic/${item.bureauId}/${item.code}.jpg">`;// 将打印的区域赋值给新窗口body,进行打印const newWindow = window.open('','');newWindow.document.write(printHTML);newWindow.window.print();//调用新窗口的打印newWindow.window.close();},:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。