First method: Specify not to print the area
Using CSS, define a. Noprint class to put the non-printed content into this class.
Details are as follows:
<style media=print type= "Text/css" >. Noprint{visibility:hidden} </style> what to print. Ha ha! <p class= "noprint" > put the non-printable code here. </p> <a href= "Javascrīpt:window.print ()" target= "_self" > Print </a>
Second method: Specify the print Area
Put the content you want to print into a span or div, and then print it through a function.
<span id= ' Div1 ' > put the content you want to print here </span> <p> All content </p> <div id= "div2" >div2 content </div> < A href= "Javascrīpt:printme ()" target= "_self" > Print </a> <scrīpt language= "javascrīpt" > Function Printme () {Document.body.innerhtml=document.getelementbyid (' Div1 '). innerhtml+ ' <br/> ' +document.getelementbyid (' Div2 '). InnerHTML; Window.print (); } </scrīpt>
If you want to print only a small part of the entire page, it's best to take the second approach.
Third method: If the page layout to be printed differs greatly from the original Web page, this method is used.
Click the Print button to pop up a new window, display the content you want to print to a new window, call the Window.print () method in a new window, and then close the new window automatically.
1, control the "vertical dozen", "horizontal dozen" and "page margin."
(1) <script defer> function setprintsettings () {//--Advanced features Factory.printing.SetMarginMeasure (2)/MEA Sure margins in inches factory. Setpagerange (False, 1, 3)//need pages from 1 to 3 Factory.printing.printer = "HP DeskJet 870C" factory.printing.copies = 2 Factory.printing.collate = True factory.printing.paperSize = "A4" Factory.printing.paperSource = "Manual feed"
--Basic features Factory.printing.header = "This was Meadco" Factory.printing.footer = "Advanced printing by ScriptX" F Actory.printing.portrait = False Factory.printing.leftMargin = 1.0 Factory.printing.topMargin = 1.0 Factory.printing.rightMargin = 1.0 Factory.printing.bottomMargin = 1.0} </script>
(2) <script language= "JavaScript" > Function Printsetup () {//Print Page Setup WB.EXECWB (8,1);} function PrintPreview () {//Print Page Preview WB.EXECWB (7,1); }
Function PrintIt () {if (confirm) (' OK to print? ') {WB.EXECWB (6,6)}} </script> print preview " onclick= "javascript: PrintPreview (); " > <input type=button name=button_fh value= "Off" onclick= "Javascript:window.close ();"
------------------------------------------------There are other uses for this component, listed below: WEBBROWSER.EXECWB (WEB.EXECWB) Open (2,1) Close all IE windows now and open a new window WEB.EXECWB (4,1) save page WEB.EXECWB (6,1) print WEB.EXECWB (7,1) print preview WEB.EXECWB (8,1) print Page Setup WEB.EXECWB (10,1) view page Properties WEB.EXECWB (15,1) appears to be revoked, pending confirmation WEB.EXECWB (17,1) Select All WEB.EXECWB (22,1) Refresh WEB.EXECWB (45,1) Close the form silently
2, pagination printing
<HTML> <HEAD> <STYLE> P {page-break-after:always} </STYLE> </HEAD> <BODY> <%whi Le not rs.eof%> <p><%=rs (0)%></p> <%rs.movenext%> <%wend%> </BODY>
3. How to remove the path at the bottom of the page and the page number at the top when the ASP page prints
(1) IE file-〉 Page Setup-〉 speak insideHeaderAndFooterEverything inside is removed and the print will not come out. (2) <HTML> <HEAD> <TITLE> New Document </TITLE> <meta name= "Generator" content= "EditPlus" > <meta name= "Author" content= "YC" > <script language= "VBScript" > Dim hkey_root,hkey_path,hkey_key Hkey_ root= "HKEY_CURRENT_USER" hkey_path= "\software\microsoft\internet explorer\pagesetup" '//Settings page printedHeaderFooterNull function Pagesetup_null () On Error Resume Next Set regwsh = CreateObject ("Wscript.Shell") hkey_key= "\header" REGWSH.R Egwrite Hkey_root+hkey_path+hkey_key, "hkey_key=" \footer "Regwsh.regwrite Hkey_root+hkey_path+hkey_key," "End function '//Set page print header footer for default function Pagesetup_default () On Error Resume Next Set regwsh = CreateObject ("Wscript.Shell") H key_key= "\header" Regwsh.regwrite hkey_root+hkey_path+hkey_key, "&w&b page, &p/&p" hkey_key= "\footer" Regwsh.regwrite Hkey_root+hkey_path+hkey_key, "&u&b&d" End Function </script> </HEAD>
<BODY> <br/> <br/> <br/> <br/> <br/> <br/><p align=center> <input Type= "button" value= "clear page number" Onclick=pagesetup_null () > <input type= "button" value= "Restore Page"
Onclick=pagesetup_default () ><br/> </p> </BODY> </HTML>
4. Floating Frame Printing
<script language=javascript> function Button1_onclick () {var odoc=window.iframe1.document; var r= Odoc.body.createTextRange (); var Stxt=r.htmltext; Alert (Stxt) var pwin=window.open ("", "print"); Pwin.document.write (Stxt); Pwin.print (); } </SCRIPT>
5. Use filesystem components for local-specific printing in Web applications
<script language=vbscript> function Print_onclick//Printing Functions Dim label Label=document.printinfo.label.value// Gets the HTML page data set Objfs=createobject ("Scripting.FileSystemObject")//creates an instance of the FileSystem Component object set OBJPRINTER=OBJFS. CreateTextFile ("LPT1:", true)//establish a connection to the printer objprinter. Writeline ("__________________________________")//output printed content Objprinter. Writeline ("| |") objprinter. Writeline ("| The data you printed is: "&label&" | " Objprinter. Writeline ("| |") objprinter. Writeline ("|_________________________________|") objprinter.close//Disconnect the printer from set objprinter=nothing set objfs= Nothing//Close FileSystem Component Object End Function </script> Server-side script: <%. Set Conn=server. CreateObject ("Adodb.connection") Conn. Open "Dsn=name; uid=xxxx; pwd=xxxx; "Set Rs=server. CreateObject ("Adodb.recordset") Rs. Open ("Select ..."), conn,1,1 ..........%>//interacting with the Database HTML page encoding: <HTML> ... <form id=printinfo name= "Printinfo" > &L T;input type= "button" value= "Print >>" Id=print name=print >//Call print function <input Type=hidden id=teXT1 Name=label value=<%=.........%>>//Save data from server side ... </HTML>
Fourth method: remove header footer
RemoveNo need to print--<input onclick=javascript:doprint () Type=button value= print name=button_print/> </p> </di V> </body>
JS Print HTML page (GO)