First, let’s explain the problem:
By default, through IE’s print dialog box, the printed content has headers and footers.
Check the page settings of IE and find the header and footer as shown in the picture on the right.
The following explains the meaning of &w&bPage&p of &P, &u&b&d
&w - window title
&u - page address
&d - short date format, such as 10/12/2006
&D - Long date format, such as Tuesday, October 12, 2006
&t - 12-hour time
&T - 24-hour time
&p - The current page number of the page
&P - The total number of pages
&& - that is &
&b - the text before the symbol is right-aligned
&b&b - the text before the first symbol is aligned in the play, and the text before the second symbol is right-aligned
Of course we The header and footer can be deleted manually. If the user just doesn’t want to modify it, they can force the modification through the following script:
var hkey_root,hkey_path,hkey_key
hkey_root="HKEY_CURRENT_USER"
hkey_path="\Software\Microsoft\Internet Explorer\PageSetup\"
// Set the header and footer of web page printing to be empty
function pagesetup_null(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh .RegWrite(hkey_root hkey_path hkey_key,"")
hkey_key="footer"
RegWsh.RegWrite(hkey_root hkey_path hkey_key,"")
}catch(e){}
}
This trick is a bit cruel, it is to modify the registry. So usually a dialog box will pop up
If you click "Yes", then as you wish, the header and footer are gone now.
Next, what if we need to recover?
Code
//Set up web page printing The header and footer are default values
function pagesetup_default(){
try{
var RegWsh = new ActiveXObject("WScript.Shell")
hkey_key="header"
RegWsh.RegWrite (hkey_root hkey_path hkey_key,"&w&bpage number,&p/&P")
hkey_key="footer"
RegWsh.RegWrite(hkey_root hkey_path hkey_key,"&u&b&d")
}catch(e){}
}
WScript.Shell (Windows Script Host Runtime Library) is an object, and the corresponding file is C:WINDOWSsystem32wshom.ocx. Wscript.shell is a component used by the server system. Shell means "shell". This object can perform common operations of the operating system shell, such as running programs, reading and writing the registry, environment variables, etc.
More WScript applications can be viewed
http://www.jb51.net/article/21296.htm