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)
<title>js print </title> 
<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 } 

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

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
} else { 
<!--startprint1--> What to print <!--endprint1--> 

2. Call the Windows bottom print, report the security warning, do not recommend to use (do not support local printing)
<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
  function printpreview(){ 
  //Print page preview

  function printit() 
  if (confirm(' Are you sure to print? ')) { 

<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  

3. JQuery implementation (support for local printing)
<script type="text/javascript" src="jquery-1.6.4.js"></script> 
<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> 

Related articles: