我想更改窗口打印的纸张模式(方向)。我想以编程方式更改它,但我找不到任何东西。
window.print()
但我不知道,我该怎么做。
@media print{@page {size: landscape}}
我不需要它。
function printWindow()
{
window.print({
/*
some code here?
*/
});
}
最佳答案
您需要为文档注入(inject)样式。
var css = '@page { size: landscape; }',
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
style.type = 'text/css';
style.media = 'print';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
window.print();
//don't forget to find and remove style if you don't want all you documents stay in landscape
关于javascript - 更改 Window.print() 纸张方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39025840/