我需要用PHP在wordpress中点击按钮打印一个包含样式的特定div。我尝试了下面的东西,但CSS不包括在内。有人能帮我吗?
null
function printDiv(DivName){
var printContents = document.getElementById(DivName).innerHTML;
var myWindow = window.open('', 'new div', 'height=400,width=600');
myWindow.document.write('<Link rel="stylesheet" href="css/style.css" type="text/css />')
myWindow.document.write('<html><body>'+printContents+'</body></html>');
myWindow.print();
myWindow.close();
return true;
}
null
试试这个代码。您需要使用media=“print”
。
function printDiv(DivName){
var printContents = document.getElementById(DivName).innerHTML;
var myWindow = window.open('', 'new div', 'height=400,width=600');
myWindow.document.write('<Link rel="stylesheet" href="css/style.css" type="text/css media="print"/>')
myWindow.document.write('<html><body>'+printContents+'</body></html>');
myWindow.print();
myWindow.close();
return true;
}