window.print()在IE中不起作用 [英] window.print() not working in IE

查看:691
本文介绍了window.print()在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在javascript中做这样的事情,点击链接打印我页面的一部分

I am doing something like this in javascript to print a section of my page on click of a link

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

它适用于Firefox,但不适用于IE。

It works great in Firefox but not in IE.

有人可以帮忙吗

推荐答案

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

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

然后打印功能将在所有浏览器中运行...

Then print function will work in all browser...

这篇关于window.print()在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆