我的页面中有一个<div>
,想要在IE / Firefox / Chrome中以横向样式打印它。
我使用此代码打印div:
function print() {
var frame = $doc.getElementsByClassName('mydivclass').item(0);
var data = frame.innerHTML;
var win = window.open('', '', 'height=500,width=900');
win.document.write('<html><head><title></title>');
win.document.write('</head><body >');
win.document.write(data);
win.document.write('</body></html>');
win.print();
win.close();
return true;
}
我发现了这个:
@page {
size: landscape;
}
但它适用于整个页面。有没有办法在景观中打印div?
答案 0 :(得分:2)
试试这个:
function print() {
var frame = document.getElementsByClassName('mydivclass').item(0);
var data = frame.innerHTML;
var win = window.open('', '', 'height=500,width=900');
win.document.write('<style>@page{size:landscape;}</style><html><head><title></title>');
win.document.write('</head><body >');
win.document.write(data);
win.document.write('</body></html>');
win.print();
win.close();
return true;
}