[英]create html page and print to new tab in javascript
將html頁面創建為內聯,並將該頁面打開到新選項卡並顯示打印視圖
我試過這個代碼但沒有工作..
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();
嘗試這個..
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();
如果窗口沒有打開..請檢查彈出窗口是否被阻止:) ..
因為你需要打開一個新的標簽然后讓它打印.. 嘗試這個..
<div id="toNewWindow">
<p>Your content here</p>
</div>
<a href="javascript:;" id="print">Open</a>
<script>
function nWin() {
var w = window.open();
var html = $("#toNewWindow").html();
$(w.document.body).html(html);
w.print();
}
$(function() {
$("a#print").click(nWin);
});</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.