<script type="text/javascript">
//Print the necessary parameters var hkey_root,hkey_path,hkey_key; hkey_root="HKEY_CURRENT_USER"; hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; // Printer setup function toPageSetup(){ document.all.WebBrowser.ExecWB( 8,1); // printer settings } // print preview function toPreview(){ document.all.WebBrowser.ExecWB(7,1); } /* * Function: print * Parameter: isShowSetup whether to display the print settings */ function printPage(isShowSetup){ pagesetup_null(); window.print(); } // Configure the header and footer of web page printing to be empty function pagesetup_null(){ try { var RegWsh = new ActiveXObject("WScript.Shell" ); hkey_key="header"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); hkey_key="footer"; RegWsh.RegWrite(hkey_root +hkey_path+hkey_key,"" ); // &b Page &p/Total &p&b } catch (e){} } </script>
Introduced in jsp:
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
Introduce styles in jsp:
<style media="print"> .Noprint { display : none //class of content not to be printed } .PageNext { page-break-after : always ; //Insert a page break after the element } </style>
Method 2: Directly import all of them, and replace the relevant content (with hints!) Just call the method
function isIE(){ if (!!window.ActiveXObject || "ActiveXObject" in window) return true; else return false; } /** * print the specified page * @return */ function printPage() { window.focus(); if(isIE()){ //$( ".td03").css("border","0px" ); var printPage=document.getElementById("divPage" );//Id of the div to be printed var oldStr= document.body.innerHTML; var newStr= printPage.innerHTML; document.body.innerHTML=newStr; pagesetup_null(); document.body.className += ' ext-ie'; document.execCommand('print', false, null); document.body.innerHTML=oldStr; return false; }else{ //$( ".td03").css("border","0px" );//Go to style var printPage=document.getElementById("divPage" );//Id of div to be printed var oldStr= document.body .innerHTML; var newStr= printPage.innerHTML; document.body.innerHTML=newStr; pagesetup_null();//Go to header and footer window.print(); document.body.innerHTML=oldStr; return false; } // Print related parameters var hkey_root, hkey_path, hkey_key; hkey_root="HKEY_CURRENT_USER"; hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; // Configure the header and footer of web page printing to be empty function pagesetup_null(){ try { var RegWsh = new ActiveXObject("WScript.Shell" ); hkey_key="header"; RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,""); hkey_key="footer"; RegWsh.RegWrite(hkey_root +hkey_path+hkey_key,"" ); // &b Page &p/Total &p&b } catch (e){} }