この記事では、すべての人向けのJS印刷の組み合わせ機能を共有しています。これは、参照を包括的です。特定のコンテンツは次のとおりです
1。ローカル印刷- どこでも印刷します
解決:
印刷したくない場所を非表示にします
<style type = "text/css" media = print>
.noprint {display:none}
ページング時に使用してください
.pagenext {page-break-after:altweer;}
次に、印刷したくないページ要素に追加すると、印刷と印刷のプレビューには表示されません。
必要なページを追加します:<div> </div>。
</style>
印刷したくない場所を制御します
<p>印刷は不要</p>
2。参照構造
WebbrowserはIEに組み込みのブラウザコントロールであり、ユーザーのダウンロードは必要ありません。
Webbrowserコントロール
<Object Id = 'webbrowser' width = 0 height = 0 classid = 'clsid:8856f961-340a-11d0-a96b-00c04fd705a2'> </object>
このコンポーネントの使用に関しては、以下がリストされています。
webbrowser.execwb(1,1)open
web.execwb(2,1)今すぐすべてのWindowsを閉じて新しいウィンドウを開きます
web.execwb(4,1)Webページを保存します
web.execwb(6,1)印刷
web.execwb(7,1)印刷プレビュー
web.execwb(8,1)印刷ページ設定
web.execwb(10,1)ページプロパティを表示します
web.execwb(15,1)はキャンセルされているようで、確認されるべきです
web.execwb(17,1)すべてを選択します
web.execwb(22,1)更新
web.execwb(45,1)フォームを静かに閉じます
3。例
<head> <スクリプト言語= "javascript"> <style type = "text/css" media = print> .noprint {display:none} </style> function printsetup(){//印刷ページ設定wb.execwb(8,1); } function printpreview(){//印刷ページプレビューwb.execwb(7,1); } function printit(){if(confism( 'print')){wb.execwb(6,6)}} </script> </head> <body> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <p> <P> <入力型= "button" name = "button_print" value = "print" onclick = "javascript:printit()" /> <input type = "button" name = "button_setup" value = "printページ設定" onclick = "javascript:printsetup();"; " /> <入力タイプ= "button" name = "button_show" value = "print preview" onclick = "javascript:printpreview();" /> </p> </body>3.JSは、シンプルなページローカル印刷を実装します
function preview(oper){if(oper <10){bdhtml = windocument.body.body.innerhtml; //現在のページsprnstr = "<! - startprint"+oper+"のHTMLコードを取得します。 prnhtml = bdhtml.substring(bdhtml.indexof(sprnstr)+18); //開始コードからhtmlを開始コードから逆に取得しますprnhtml = prnhtml.substring(0、prnhtml.indexof(eprnstr)); window.print(); window.document.body.innerhtml = bdhtml;} else {window.print(); }}ページに印刷するコンテンツを真ん中に追加するのは非常に簡単です<! - startprint1-> xxxx <! - endprint1-> - >
別の印刷ボタンを追加onclick =プレビュー(1)
4。「垂直ヒット」、水平ヒット」、「ページ」のマージンを制御します。
(1)<スクリプトDefer>
function setPrintSettings(){//- Advanced Feature Factory.Printing.setMarginMeasure(2)//インチのfactory.setpagerange(false、1、3)//必要なページ1から3 Factory.printing.printing.printer.printer = "hp Deskjet 870c" Factory.printing.copies = 2 Factory.printingcoltedcoltedingcoltingcoltingcoltingcolting。 Factory.printing.papersize = "a4" factory.printing.papersource = "Manual Feed" // - 基本機能Factory.printing.header = "これはmeadco" factory.printing.footer = "scriptx" factory.printing.portrait.portrait.portory.printing.leftmargin = 1.0 factory.print.portory.portory.portory.portory.portory.portory.portory.portory.portory.portory. Factory.printing.rightmargin = 1.0 Factory.printing.bottommargin = 1.0} </script> function preview(oper){if(oper <10){bdhtml = document.body.innerhtml; //現在のページのhtmlコードを取得eprnstr = "<! - endprint"+oper+" - >"; //プリントエンド領域を設定しますprnhtml = bdhtml.substring(bdhtml.indexof(sprnstr)+18); // html prnhtml = prnhtml.substring(0、prnhtml.indexof(eprnstr)); // html window.document.body.innerhtml = prnhtmlを取得します。 window.print(); window.document.body.innerhtml = bdhtml;} else {window.print(); }}ページに印刷するコンテンツを真ん中に追加するのは非常に簡単です<! - startprint1-> xxxx <! - endprint1-> - >
別の印刷ボタンを追加onclick =プレビュー(1)
JS印刷機能の詳細については、「JS印刷機能の概要」をクリックして学習します
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。