【发布时间】:2011-08-01 16:00:04
【问题描述】:
我可以通过 javascript window.print(); 获得打印对话,但我无法将其更改为横向。用 jquery 或任何方式都可以吗?
编辑
如果没有,有解决办法吗?
【问题讨论】:
标签: javascript jquery css printing
我可以通过 javascript window.print(); 获得打印对话,但我无法将其更改为横向。用 jquery 或任何方式都可以吗?
编辑
如果没有,有解决办法吗?
【问题讨论】:
标签: javascript jquery css printing
我找到了 IE6 的解决方案,但没有找到 IE7 或 Firefox
<script type="text/javascript">
var shell;
function SetPrintProperties() {
try {
shell = new ActiveXObject("WScript.Shell");
shell.SendKeys("%fu");
window.setTimeout("javascript:SetPaperSize();", 1200);
window.setTimeout("javascript:setLandScape();", 2000);
} catch (e) {
alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
}
}
function SetPaperSize() {
shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
}
function setLandScape() {
shell.sendKeys("%fp");
window.print();
}
</script>
<body onload="SetPrintProperties()">
【讨论】:
我认为您应该让浏览器处理打印并为其设置特定的 CSS。
<link rel="stylesheet" type="text/css" href="style.css" media="print" />
【讨论】:
这是一个打印机软件特定的问题,如果没有大量的 javascript 黑客攻击,您将无法做到这一点。
【讨论】:
<script language="javascript" type="text/javascript">
var shell = new ActiveXObject("WScript.Shell");
function SetPrintProperties() {
try {
window.setTimeout("BLOCKED SCRIPTshell.SendKeys('%fu');",1);
window.setTimeout("BLOCKED SCRIPTSetPaperSize();", 1);
print();
} catch (e) {
alert ("An exception occured: " + e + "\nCode is: " + e.number + "\nDescription is: " + e.description);
alert('Please verify that your print settings have a Landscape orientation and minimum margins.');
}
}
function SetPaperSize() {
shell.sendKeys("%a{TAB}.2{TAB}0{TAB}0{TAB}0{ENTER}");
}
SetPrintProperties();
</script>
【讨论】: