Js or jquery page printing can be printed locally

  • 2020-03-30 02:29:55
  • OfStack

Js or jquery page printing (partial printing)

1. Js implementation (partial printing)
 
<html> 
<title>js print </title> 
<head></head><body> 
<input id="btnPrint" type="button" value=" print " onclick="javascript:window.print();" /> 

<input id="btnPrint" type="button" value=" Print preview " onclick=preview(1) /> 
<style type="text/css" media=print> 
.noprint{display : none } 
</style> 


<p class="noprint"> No place to print </p> 

<script> 
function preview(oper) 
{ 
if (oper < 10) 
{ 
bdhtml=window.document.body.innerHTML;//Gets the HTML code for the current page
sprnstr="<!--startprint"+oper+"-->";//Set the print start area
eprnstr="<!--endprint"+oper+"-->";//Set the end of print area
prnhtml=bdhtml.substring(bdhtml.indexOf(sprnstr)+18); //Fetch the HTML back from the starting code

prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));//Fetch the HTML forward from the closing code
window.document.body.innerHTML=prnhtml; 
window.print(); 
window.document.body.innerHTML=bdhtml; 
} else { 
window.print(); 
} 
} 
</script> 
<p>XXXXX</p> 
<!--startprint1--> What to print <!--endprint1--> 
</body> 
</html> 

2. Call the Windows bottom print, report the security warning, do not recommend to use (do not support local printing)
 
<HTML> 
<HEAD> 
<TITLE>javascript print - Print page Settings - Print preview code </TITLE> 
<META http-equiv=Content-Type content="text/html; charset=gb2312" /> 
<SCRIPT language=javascript> 
  function printsetup(){ 
  //Print page Settings
  wb.execwb(8,1); 
  } 
  function printpreview(){ 
  //Print page preview
     
  wb.execwb(7,1);       
     
  } 

  function printit() 
  { 
  if (confirm(' Are you sure to print? ')) { 
  wb.execwb(6,6); 
  } 
  } 
  </SCRIPT> 
</HEAD> 
<BODY> 

<DIV align=center> 
<OBJECT id=wb height=0 width=0 
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT> 
<INPUT onclick=javascript:printit() type=button value= print  name=button_print /> 
<INPUT onclick=javascript:printsetup(); type=button value= Print page Settings  name=button_setup /> 
<INPUT onclick=javascript:printpreview(); type=button value= Print preview  name=button_show /> 
 Press the beginning of the weight loss card period  
</DIV> 
</BODY> 
</HTML> 

3. JQuery implementation (support for local printing)
 
<html> 
<head> 
<script type="text/javascript" src="jquery-1.6.4.js"></script> 
<script> 
$(function(){ 
$("input#biuuu_button").click(function(){ 
$("div#myPrintArea").printArea(); 
}); 
</script> 
</head> 
<body> 
<input id="biuuu_button" type="button" value=" print "></input> 
<div id="myPrintArea">..... Text print .....</div> <div class="quote_title"> reference </div><div class="quote_div"></div> 
</body> 
</html> 

Related articles: