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:

WEBBROWSER.EXECWB (1,1) turns 
on WEB.EXECWB (2,1) closes all the IE windows now and opens a new window 
WEB.EXECWB (4,1) to save the 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 

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.


<script language=javascript> var Hkey_root,hkey_path,hkey_key; 
Hkey_root= "HKEY_CURRENT_USER"; 
Hkey_path= "\\Software\\Microsoft\\Internet explorer\\pagesetup\\";

var head,foot,top,bottom,left,right; 
  Gets the original parameter data function pagesetup_temp () {try {var wsh=new activexobject ("Wscript.Shell") of the page print settings; 
hkey_key= "Header"; 
  Gets the header default value head = Wsh.regread (Hkey_root+hkey_path+hkey_key); 
hkey_key= "Footer"; 
  Gets the footer default value foot = Wsh.regread (Hkey_root+hkey_path+hkey_key); 
Hkey_key= "Margin_bottom"; 
  Gets the next margin bottom = Wsh.regread (Hkey_root+hkey_path+hkey_key); 
Hkey_key= "Margin_left"; 
  To get left-margin left-hand = Wsh.regread (Hkey_root+hkey_path+hkey_key); 
Hkey_key= "Margin_right"; 
  To get right to the right-hand side (Wsh.regread) (Hkey_root+hkey_path+hkey_key); 
Hkey_key= "Margin_top"; 
 Get top = Wsh.regread (hkey_root+hkey_path+hkey_key) of upper margin;
 catch (E) {alert ("Do not allow ActiveX controls"); 
  }//Set Page Header footer and page margins function pagesetup_null () {try {wsh=new ActiveXObject ("Wscript.Shell"); Hkey_key= "Header"; 
  Set the header (blank) wsh.regwrite (Hkey_root+hkey_path+hkey_key, ""); 
hkey_key= "Footer"; 
  Set footer (empty) wsh.regwrite (Hkey_root+hkey_path+hkey_key, ""); 
Hkey_key= "Margin_bottom"; 
  Set the next page margin (0) wsh.regwrite (Hkey_root+hkey_path+hkey_key, "0"); 
Hkey_key= "Margin_left"; 
  Set left margins (0) wsh.regwrite (Hkey_root+hkey_path+hkey_key, "0"); 
Hkey_key= "Margin_right"; 
  Set right margin (0) wsh.regwrite (Hkey_root+hkey_path+hkey_key, "0"); 
Hkey_key= "Margin_top"; 
 Set up margin (8) wsh.regwrite (Hkey_root+hkey_path+hkey_key, "8");
 catch (E) {alert ("Do not allow ActiveX controls"); 
  }//Set page header footer and margins as default value function Pagesetup_default () {try {var wsh=new activexobject ("Wscript.Shell"); 
  hkey_key= "Header"; 
hkey_key= "Header"; 
  Restore Header Wsh.regwrite (hkey_root+hkey_path+hkey_key,head); 
hkey_key= "Footer"; 
  Restore Footer Wsh.regwrite (hkey_root+hkey_path+hkey_key,foot); 
Hkey_key= "Margin_bottom"; 
  Restore the next margin wsh.regwrite (Hkey_root+hkey_path+hkey_key,bottom); 
Hkey_key= "Margin_left";
 Restore left margins Wsh.regwrite (Hkey_root+hkey_path+hkey_key,left); 
Hkey_key= "Margin_right"; 
  Restore right margin wsh.regwrite (hkey_root+hkey_path+hkey_key,right); 
Hkey_key= "Margin_top"; 
 Restores upper margin wsh.regwrite (hkey_root+hkey_path+hkey_key,top);
 catch (E) {alert ("Do not allow ActiveX controls"); } function Printorder () {pagesetup_temp ();//Get default value Pagesetup_null ();/Set page FACTORY.EXECWB (6,6);//Print page PageSetup
		_default ();//Restore page Settings//FACTORY.EXECWB (6,6);
Window.close (); } </script> <object id=factory height=0 width=0 classid=clsid:8856f961-340a-11d0-a96b-00c04fd705a2></ Object>


Related Article

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.