我一直在争取相当一段时间的这个问题,并已(仍然)无法打印我的div的样式。无法插入样式表/脚本到window.open
目前,我的脚本是:
$('#printMeButton').click(function() {
//alert("a");
var data = document.getElementById('thisPrintableTable').outerHTML;
var mywindow = window.open('', data);
mywindow.document.write('<html><head><title>Print Me!!!</title>');
// mywindow.document.write('<link rel="stylesheet" type="text/css" href="Site.css" media="screen">');
mywindow.document.write('</head><body>');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
return true;
});
其嵌套在$(document).ready
函数中。
当我包含所需的样式表(当前注释掉)时,打印预览中不显示任何内容。
我也有一些脚本对表的外观有影响,因此,我相信这可能会把这些包含到弹出窗口中的关键。
我该如何将这个包含到新的弹出窗口中?
有人可以请建议一种打印方式,因为它的立场?
编辑历史
- 在
</head><body>
- 改变
var data
末除去了空间有outerHTML
代替innerHTML
- 改变的问题/从更好地了解问题 的细节
你能否扩展/详细说明这一点?我有点理解这种可能性,但不是执行 – jbutler483 2014-12-03 10:42:58
我已经添加了一些代码。现在检查它。 – Indra 2014-12-03 12:46:40