[英]Problems with javascript print function
我有這個JavaScript代碼可以從PHP文檔中打印html表。
function printReport()
{
var data = '<input type="button" value="Print this page" onClick="window.print()">';
data += '<input type="button" value="Close this page" onClick="window.close()">';
data += '<table border="0"';
data += $('#reportTable').html();
data += '</table>';
myWindow=window.open('','','scrollbars=yes,resizable=yes,width=500,height=400');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.write(data);
myWindow.focus();
};
它會打開新窗口,向右顯示內容,關閉按鈕可以正常使用,但是打印按鈕無效。
我的打印機可以正常工作,我可以通過Word或任何其他應用程序進行打印,並且可以正常工作。
我的問題是:打印功能window.print()
正常工作。
如果有人可以幫我,將不勝感激。
干杯
更改:
data += '<table border="0"';
至
data += '<table border="0">';
告訴我們最終結果。 使用表中的簡單HTML內容進行了測試。 假設您的.html()
調用返回有效的表數據,則該窗口現在應該可以打印了。
在這里工作的小提琴: http : //jsfiddle.net/aV85r/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.