JavaScript Print encyclopedia (print page setup/print Preview code) _javascript Tips

Source: Internet
Author: User
Copy Code code as follows:

<meta http-equiv=content-type content= "text/html; charset=gb2312 "/>
<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>
</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 Setup name=button_setup/>
<input Onclick=javascript:printpreview (); Type=button value= Print Preview Name=button_show/>
</DIV>
</BODY>
</HTML>

JavaScript Print Encyclopedia
(1)
Copy Code code as follows:

<script. Defer>
function Setprintsettings () {
--Advanced Features
Factory.printing.SetMarginMeasure (2)//measure 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 is Meadco"
Factory.printing.footer = "Advanced printing by ScriptX"
Factory.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)
Copy Code code as follows:

<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>
<body>
<object classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"
Height=0 ID=WB NAME=WB width=0></object>
<input Type=button name=button_print value= "print"
onclick= "JavaScript.:p rintit ()" >
<input Type=button name=button_setup value= "Print Page Setup"
onclick= "JavaScript.:p rintsetup ();" >
<input Type=button name=button_show value= "Print Preview"
onclick= "JavaScript.:p Rintpreview ();" >
<input Type=button name=button_fh value= "Off"
Onclick= "Javascript.:window.close ();" >

------------------------------------------------
There are other uses for this component, listed below
WEBBROWSER.EXECWB (1,1) Open
WEB.EXECWB (2,1) closes all of the IE windows now and opens a new window
WEB.EXECWB (4,1) Save Web page
WEB.EXECWB (6,1) printing
WEB.EXECWB (7,1) Print preview
WEB.EXECWB (8,1) print Page Setup
WEB.EXECWB (10,1) view page Properties
WEB.EXECWB (15,1) seems to be withdrawn, pending confirmation
WEB.EXECWB (17,1) Select all
WEB.EXECWB (22,1) Refresh
WEB.EXECWB (45,1) Close the form without prompting
2, Paging printing
Copy Code code as follows:

<HTML>
<HEAD>
<STYLE>
P {Page-break-after:always}
</STYLE>
</HEAD>
<BODY>
<%while not rs.eof%>
<p><%=rs (0)%></p>
<%rs.movenext%>
<%wend%>
</BODY>
</HTML>

3. How to get rid of the path at the bottom of the page and the number of the top page when printing ASP page
(1) IE file-〉 page settings-〉 said inside the header and footer inside of the things are removed, printing will not come out.
(2)
Copy Code code as follows:

<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"
'//Set page to print header and footer empty
function Pagesetup_null ()
On Error Resume Next
Set regwsh = CreateObject ("Wscript.Shell")
hkey_key= "\header"
Regwsh.regwrite Hkey_root+hkey_path+hkey_key, ""
hkey_key= "\footer"
Regwsh.regwrite Hkey_root+hkey_path+hkey_key, ""
End Function
'//Set the page header footer as the default value
function Pagesetup_default ()
On Error Resume Next
Set regwsh = CreateObject ("Wscript.Shell")
hkey_key= "\header"
Regwsh.regwrite hkey_root+hkey_path+hkey_key, "&w&b page number, &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= "empty page number" Nclick=pagesetup_null () > <input type= "button" value= "Recovery page" nclick= Pagesetup_default () ><br/>
</p>
</BODY>
</HTML>

4, floating frame printing
Copy Code code as follows:

<script. Language=javascript>
function Button1_onclick () {
var doc=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, using the FileSystem component to implement the local specific printing in the Web application
Copy Code code as follows:

<script. Language=vbscript>
function Print_onclick//print functions
Dim label
Label=document.printinfo.label.value//Access to HTML page data
Set Bjfs=createobject ("Scripting.FileSystemObject")//Create an instance of the FileSystem Component object
Set BJPRINTER=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 from the printer
Set bjprinter=nothing
Set bjfs=nothing//close FileSystem Component Object
End Function
</script>

server-side scripting
Copy Code code as follows:

<% .....
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
Copy Code code as follows:

<HTML>
.........
<form. Id=printinfo name= "Printinfo" >
<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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.