我尝试从div复制内容,创建新窗口并将内容放入其中。
代码是工作,但没有得到的样式。我怎么能复制所有的样式引用从源页面?
附言:我用的是bootstrap + react
function PrintElem() {
var nWindow = window.open('', 'PRINT', 'height=400,width=600');
let content = document.getElementById('printablediv').innerHTML;
content.print();
nWindow.document.write('<html><head><title>' + document.title + '</title>');
nWindow.document.write('</head><body >');
nWindow.document.write(content);
nWindow.document.write('</body></html>');
nWindow.document.close();
nWindow.focus();
nWindow.print();
}
1条答案
按热度按时间oyt4ldly1#
我发现了如何:你需要复制头属性,这是css引用的地方。