因此,讓我們先從代碼:沒有攜帶樣式表JavaScript的打印功能
var mywindow = window.open('', 'PRINT', 'height=600,width=800');
mywindow.document.write('<html><head><base href="/" /><title>' + document.title + '</title>');
mywindow.document.write('<style type="text/css" media="print" />table { width: 100%; }</style>');
mywindow.document.write('</head><body >');
mywindow.document.write('<h1> Returns for Today </h1>');
mywindow.document.write(document.getElementById(printableArea).innerHTML);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10*/
mywindow.print();
mywindow.close();
return true;
的代碼是相當有這個輸出工作
,然後當我更改CSS到外部樣式表如下:
從mywindow.document.write('<style type="text/css" media="print" />table { width: 100%; }</style>');
要mywindow.document.write('<link rel="stylesheet" href="assets/css/printstyles.css" type="text/css" />');
我得到了一個空白打印頁:
但如果我評論的線
//mywindow.print();
//mywindow.close();
我得到這個:
含義,外部樣式表正在工作。
外部樣式表僅包括
table { width: 100%; }
任何想法,爲什麼它不工作?任何幫助將非常感激。
參見[保存預元素作爲CSS PDF](http://stackoverflow.com/q/30135765/) – guest271314
添加媒體=」打印「到您的外部樣式表的引用。 – jeff
@jeff,做到了這一點,它的工作雖然沒有風格哈哈 – FewFlyBy