Tah*_*idi 3 javascript css printing
我的页面中有一个<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;
}
Run Code Online (Sandbox Code Playgroud)
我找到了这个:
@page {
size: landscape;
}
Run Code Online (Sandbox Code Playgroud)
但它只适用于整个页面。有没有办法横向打印div?
尝试这个:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9476 次 |
| 最近记录: |