JavaScript to implement Web page printing, you can set the header, footer, margin __java
Source: Internet
Author: User
WebBrowser is the IE built-in browser control, without the user download, you can implement the client page printing.
There are other uses for this component, as listed below:
Code:
The meaning of a function is as follows------
1.WEBBROWSER.EXECWB (1,1) Open
2.WEB.EXECWB (2,1) closes all of the IE windows now and opens a new window
3.WEB.EXECWB (4,1) Save Web page
4.WEB.EXECWB (6,1) printing
5.WEB.EXECWB (7,1) Print preview
6.WEB.EXECWB (8,1) print Page Setup
7.WEB.EXECWB (10,1) view page Properties
8.WEB.EXECWB (15,1) seems to be withdrawn, pending confirmation
9.WEB.EXECWB (17,1) Select all
10.WEB.EXECWB (22,1) Refresh
11.WEB.EXECWB (45,1) Close the form without prompting
Note that when possible, there will be no effect errors, because it is possible that your browser restricts the creation of active objects, so long as you remove the restrictions, the cancellation method is as follows:
Open your IE browser Internet option-security-Custom level-to initialize ActiveX controls that are not marked as safe and script run to enable.
Code:
1.<script language=javascript>
2.var Hkey_root,hkey_path,hkey_key;
3.hkey_root= "HKEY_CURRENT_USER";
4.hkey_path= "\\Software\\Microsoft\\Internet explorer\\pagesetup\\";
5.var Head,foot,top,bottom,left,right;
6.
7.//get the original parameter data of the page print Setup
8.function Pagesetup_temp () {
9. Try
10. {
One. Var wsh=new activexobject ("Wscript.Shell");
hkey_key= "Header";
13.//get the default value for headers
Head = Wsh.regread (Hkey_root+hkey_path+hkey_key);
hkey_key= "Footer";
16.//Get footer Default value
Foot = Wsh.regread (Hkey_root+hkey_path+hkey_key);
Hkey_key= "Margin_bottom";
19.//get the next page margin
Bottom = Wsh.regread (Hkey_root+hkey_path+hkey_key);
Hkey_key= "Margin_left";
22.//Get left margins
left = Wsh.regread (Hkey_root+hkey_path+hkey_key);
Hkey_key= "Margin_right";
25.//Get right margin
right = Wsh.regread (Hkey_root+hkey_path+hkey_key);
Hkey_key= "Margin_top";
28.//Get top margin
top = Wsh.regread (Hkey_root+hkey_path+hkey_key);
30.}
catch (e) {
Alert ("Do not allow ActiveX controls");
33.}
34.}
35.
36.//Set page headers, footers, and margins to print
37.function Pagesetup_null ()
38.{
Try
40. {
var wsh=new activexobject ("Wscript.Shell");
hkey_key= "Header";
43.//Set Header (blank)
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "");
hkey_key= "Footer";
46.//set footer (blank)
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "");
Hkey_key= "Margin_bottom";
49.//Set next page margin (0)
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "0");
Wuyi hkey_key= "Margin_left";
52.//set left margin (0)
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "0");
Hkey_key= "Margin_right";
55.//Set right margins (0)
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "0");
Hkey_key= "Margin_top";
58.//set up page margins (8)
Wsh.regwrite (Hkey_root+hkey_path+hkey_key, "8");
60.}
catch (e) {
Alert ("Do not allow ActiveX controls");
63.}
64.}
65.//set page headers and footers to print and margins as defaults
66.function Pagesetup_default ()
67.{
A. Try
69. {
var wsh=new activexobject ("Wscript.Shell");
hkey_key= "Header";
hkey_key= "Header";
73.//Restore Header
Wsh.regwrite (Hkey_root+hkey_path+hkey_key,head);
hkey_key= "Footer";
76.//Restore Footer
Wsh.regwrite (Hkey_root+hkey_path+hkey_key,foot); &nb
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