1.首先需要安装ScriptX。官网地址:MeadCo's ScriptX (meadroid.com)http://scriptx.meadroid.com/download/download-developer-resource-kit.aspx
2.
<OBJECT id="factory" style="DISPLAY: none" codeBase="ScriptX.cab" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext>
</OBJECT>
<script language="javascript" type="text/javascript">
function doprint() {
var g_ScriptXObj = new ActiveXObject("ScriptX.factory");
var g_ControlInstalled = true;
//document.getElementById("warningmsg").style.display="none";
factory.printing.header = ""; //页眉
factory.printing.footer = ""; //页脚
factory.printing.portrait = true; //横向打印
//页边距
factory.printing.Print(false); //设置为false 直接打印 也可用 factory.DoPrint(false);
factory.printing.leftMargin = 0
factory.printing.topMargin = 0
factory.printing.rightMargin = 0
factory.printing.bottomMargin = 0
window.print();
window.close();
}
</script>
3.IE11上可能会出现打印不了的问题,设置浏览器的的安全属性和兼容性问题,如下图所示:
把两个设置上就可以了,有的电脑只需要设置一个就可以了,不知道啥情况,两个都装上最保险。