window.print()打印页面

  • Post author:
  • Post category:其他



使用window.print()打印页面内容时


1、可以删除不必要dom标签构建一个适合打印的页面,然后执行window.print()。


2、在重新加载页面还原修改的页面

	doPrint : function(jgtz_id){
		
		//var older = document.body.innerHTML;
		
		$("a[class=font-red]").each(function(){
			    $(this).remove();
		});
		
		$("div[class=insertTab]").css('width','700px');
		$("table[class=sq]").css('width','700px');
		               
		var sMM = "<style media='print'> @page {size: auto; margin: 0mm;  }</style>";
        var head_str = "<html><head><title></title></head><body><div style='height:30px;width:100%;'></div><div id='baac'>" + sMM; //先生成头部
        var new_str = document.getElementById('printBody').innerHTML; //获取指定打印区域
        var foot_str = "</div></body></html>"; //生成尾部
        document.body.innerHTML = head_str + new_str + foot_str; //构建新网页
        window.print(); //打印刚才新建的网页
        
        window.location.reload();
        return false;
	}



版权声明:本文为weixin_37906108原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。