| | |
| | | const inspection = () => { }; |
| | | |
| | | const print = () => { |
| | | const imageUrls = ['https://www.baidu.com/img/flexible/logo/pc/result@2.png',] |
| | | const iframe = document.createElement('iframe'); |
| | | iframe.style.display = 'none'; |
| | | document.body.appendChild(iframe); |
| | | // const imageUrls = ['https://www.baidu.com/img/flexible/logo/pc/result@2.png',] |
| | | // const iframe = document.createElement('iframe'); |
| | | // iframe.style.display = 'none'; |
| | | // document.body.appendChild(iframe); |
| | | |
| | | const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; |
| | | iframeDoc.open(); |
| | | iframeDoc.write('<html><head><title>Print Images</title></head><body>'); |
| | | // const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; |
| | | // iframeDoc.open(); |
| | | // iframeDoc.write('<html><head><title>Print Images</title></head><body>'); |
| | | |
| | | // 将图片插入到 iframe 中 |
| | | imageUrls.forEach((imageUrl) => { |
| | | iframeDoc.write(`<img src="${imageUrl}" style="margin: 10px;">`); |
| | | }); |
| | | // // 将图片插入到 iframe 中 |
| | | // imageUrls.forEach((imageUrl) => { |
| | | // iframeDoc.write(`<img src="${imageUrl}" style="margin: 10px;">`); |
| | | // }); |
| | | |
| | | iframeDoc.write('</body></html>'); |
| | | iframeDoc.close(); |
| | | // iframeDoc.write('</body></html>'); |
| | | // iframeDoc.close(); |
| | | |
| | | // 等待图片加载完成后触发打印 |
| | | iframe.contentWindow.onload = () => { |
| | | iframe.contentWindow.print(); |
| | | // 打印完成后移除 iframe |
| | | document.body.removeChild(iframe); |
| | | }; |
| | | // // 等待图片加载完成后触发打印 |
| | | // iframe.contentWindow.onload = () => { |
| | | // iframe.contentWindow.print(); |
| | | // // 打印完成后移除 iframe |
| | | // document.body.removeChild(iframe); |
| | | // }; |
| | | }; |
| | | |
| | | |