web 打印指定内容

来源:互联网 发布:虚拟化桌面软件 编辑:程序博客网 时间:2024/05/21 10:42
需要执行一段Javascript代码,也是重点部分,这段Javascript放置在.aspx页最未端部分,也就是让网页最后执行。 复制代码 代码如下:
function PrintArticle() { 

var printarea = document.getElementById("元素id"); 

//大小设置

var pw = window.open('', '', 'width=800,height=600'); 
pw.document.write('<html>'); 
pw.document.write('<head>'); 
pw.document.write('<title>XX报表</title>'); 
pw.document.write('</head>'); 
pw.document.write('<body>'); 
pw.document.write(printarea.innerHTML); 
pw.document.write('</body>'); 
pw.document.write('</html>'); 
pw.document.close(); 

setTimeout(function () {

//调用print 

pw.print(); 
}, 500); 
return false; 

上面打印出来的有点点问题,就是web打印出来的会有页头,页脚为url

可以在打印的页面设置中去掉


原创粉丝点击