Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

jquery - create html page and print to new tab in javascript

create html page as inline and that page open to new tab and show print view

i tried with this code but not working..

     var mywindow = window.open('', 'Print  Report', 'height=400,width=600');
     mywindow.document.write('<html><head><title>Print  Report</title>');
     mywindow.document.write('</head><body ><table  border="1" style="width: 500px; height: 300px;">');
     mywindow.document.write(htmlTable);
     mywindow.document.write('</table></body></html>');
     mywindow.open().print();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try this..

var winPrint = window.open('', '', 'left=0,top=0,width=800,height=600,toolbar=0,scrollbars=0,status=0');
winPrint.document.write('<title>Print  Report</title><br /><br /> Hellow World');
winPrint.document.close();
winPrint.focus();
winPrint.print();
winPrint.close(); 

if the window is not open .. please check whether the popup is blocked :)..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...