2016-12-05 26 views
0

我想從瀏覽器的第二頁到第二頁打印, 如何在javascript中調用window.print();之前指定範圍。如何以編程方式指定要在瀏覽器中打印的頁面範圍(使用javascript或css)

這是我的風格爲介質打印

<style type="text/css" media="print"> .pageBreak { page-break-before: avoid; page-break-after: avoid; page-break-inside: avoid; height: 100%; } @page { size: landscape; } </style>

感謝

+0

http://vikku.info/codesnippets/javascript/print-div-content-print-only-the-content-of-an-html-element-and-not-the-whole-document/這會有幫助嗎您? – lsof

+0

將您想要的內容放入'div'並將其內容加載到打印窗口中。 – lsof

回答

0

希望這會幫助你

Java腳本

var content = document.getElementById(「mycontenttoprint"); 
var printer = document.getElementById(「printiframe").contentWindow; 
printer.document.open(); 
printer.document.write(content.innerHTML); 
printer.document.close(); 
printer.focus(); 
printer.print(); 

HTML

<iframe id="printiframe" style="height: 0px; width: 0px; position: absolute"></iframe> 

請讓我知道,如果你面對任何困難。

+0

感謝@Rajasuba,我想要實現的是,當調用'window.print();'時,能夠務實地將範圍放在打印預覽對話框中。你能幫我解決嗎? – Laxman

相關問題