1. Window. Print mode:
JSP page printing button:
<Input type = "button" value = "print" onclick = "Print ();">
JS:
Function print (){
Window. Print ();
In the style, set the hide button to print:
<Style>
@ Media Print {
. Noprint {display: None}
}
</Style>
2. webbrowser Control Mode
Webbrowser is a browser control built in IE, which does not need to be downloaded by users.
I. webbrowser Control
<Object ID = 'webbrowser 'width = 0 Height = 0 classid = 'clsid: 8856f961-340a-11d0-a96b-00c04fd705a2 '> </Object>
2. webbrowder Control Method
// Print
Webbrowser1.execwb (6, 1 );
// Print settings
Webbrowser1.execwb (8, 1 );
// Print and preview
Webbrowser1.execwb (7,1 );
There are other usage examples of this component:
Webbrowser. execwb () Open
Web. execwb () Close all existing IE Windows and open a new window
Web. execwb () save Web Page
Web. execwb (6, 1) Printing
Web. execwb (7,1) print and preview
Web. execwb (8, 1) Printing page settings
Web. execwb () view page properties
Web. execwb () seems to be undo, to be confirmed
Select all web. execwb ()
Web. execwb (22, 1) Refresh
Web. execwb () Close form no prompt
However, printing prints the entire page, and prints out anything on the page. Sometimes we only need to print the data table, and then we need to write a style: hide the part that you do not want to print:
Style content:
<Style type = "text/CSS" Media = print>
. Noprint... {display: None}
</Style>
Then you can use the style:
<P class = "noprint"> No printing required </P>
The Code is as follows:
<Script language = "JavaScript">
Function printsetup ()...{
// Print page settings
Wb.exe CWB (8, 1 );
Function printpreview ()...{
// Print the Page Preview
Wb.exe CWB (7,1 );
Function printit ()
...{
If (confirm ('Are you sure you want to print? '))...{
Wb.exe CWB (6, 6)
</SCRIPT>
<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" class = "noprint" onclick = "javascript: printit ()">
<Input type = button name = button_setup value = "print page settings" class = "noprint" onclick = "javascript: printsetup ();">
<Input type = button name = button_show value = "print preview" class = "noprint" onclick = "javascript: printpreview ();">
3. Remove the header and footer <HTML> // Hide the elements that do not want to print the output before printing (in this example, the "print" and "print preview" buttons are hidden) var olesponid = 7; var prompt = 1; vaR webbrowser = '<Object ID = "webbrowser1" width = 0 Height = 0 classid = "CLSID: 8856f961-340a-11d0-a96b-00c04fd705a2"> </Object>'; document. body. insertadjacenthtml ('beforeend', webbrowser );
Webbrowser1.execwb (oleodiid, prompt); webbrowser1.outerhtml = ""; document. all ("dayindiv "). style. display = ""; // display this element after printing (the "print" and "print preview" buttons are displayed for others to print them next time)} function printture () // print the function {document. all ('qingkongyema '). click (); // same as document. all ("dayindiv "). style. display = "NONE"; // same as above
Window. print (); document. all ("dayindiv "). style. display = "";} function dopage () {layloading. style. display = "NONE"; // same as above} </SCRIPT> <script language = "VBScript"> dim hkey_root, hkey_path, hkey_key hkey_root = "HKEY_CURRENT_USER" hkey_path = "\ Software \ Microsoft \ Internet
Explorer \ pagesetup "'// set the page header and footer to null 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 default value of the page header and footer to 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> Type = "button" class = "tab" value = "print" onclick = "printture (); "> <input type =" button "class =" tab "value =" print preview "onclick =" printpr (); "> <input type =" hidden "name =" qingkongyema "id =" qingkongyema "class =" tab "value =" Clear page number "onclick =" pagesetup_null () "> <input type =" hidden"
Class = "tab" value = "Restore page number" onclick = "pagesetup_default ()"> </div> </body>