javascript - window.print() 在 IE 中不工作

标签 javascript internet-explorer printing

我正在用 javascript 做这样的事情,以在单击链接时打印我的页面的一部分

function printDiv() {
 var divToPrint = document.getElementById('printArea');
 var newWin = window.open();
 newWin.document.write(divToPrint.innerHTML);
 newWin.print();
 newWin.close();
}

它在 Firefox 中运行良好,但在 IE 中运行不佳。

有人可以帮忙吗

最佳答案

newWin.document.write(divToPrint.innerHTML) 之后添加这些行

newWin.document.close();
newWin.focus();
newWin.print();
newWin.close();

然后打印功能将在所有浏览器中工作...

关于javascript - window.print() 在 IE 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2555697/

相关文章:

javascript - RegEx 解析日志文件中的一行

javascript - 用 JS 检查时 IE 8 的版本错误

javascript - IE 9 错误 - 'SCRIPT600 : Invalid target element for this operation

javascript - 元素的 FormData 不起作用 - Internet Explorer 10

macos - CUPS 打印机未显示在打印机对话框中

c - 打印链表结构C

javascript - 如何对文本 Angular 应用最大字数验证

javascript - 只想比较 TIME 值 MomentJS

ios - 如何将完整的 uicollectionview 打印到图像或 pdf 中

javascript - 为什么不能映射 'undefined' 数组