2011-08-01 57 views

回答

2

我已經找到了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()"> 
0

這是一個打印機軟件特定的問題,如果沒有使用javascript進行大量的hackery,您將無法做到這一點。

1

我認爲你應該讓瀏覽器處理打印並設置一個特定的CSS。

<link rel="stylesheet" type="text/css" href="style.css" media="print" /> 
+1

這是什麼呢?我只是把它放在head標籤中,瀏覽器會知道頁面應該是橫向還是縱向的時候? – code511788465541441

0
 

<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> 
 
+0

它不工作。它說預計';'在第1行,但我沒有看到任何半collon任務。你嘗試過哪種瀏覽器?對任何打印機軟件來說這也是一個空間? – code511788465541441

相關問題