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 ();">
----------------------------------------------------------------------
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
<SCRIPT type = "text/JavaScript">
VaR 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 be empty.
Function pagesetup_null ()
{
Try {
VaR wsh = new activexobject ("wscript. Shell ");
Hkey_key = "Header ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key ,"");
Hkey_key = "footer ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key ,"");
} Catch (e ){}
}
// Restore the page header and footer
Function pagesetup_default ()
{
Try {
VaR wsh = new activexobject ("wscript. Shell ");
Hkey_key = "Header ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key, "& W & B page number, & P/& P ");
Hkey_key = "footer ";
Wsh. regwrite (hkey_root + hkey_path + hkey_key, "& U & B & D ");
} Catch (e ){}
}
Function printsetup (){
// Print page settings
Wb.exe CWB (8, 1 );
}
Function printpreview (){
// Print the Page Preview
Pagesetup_null ();
Wb.exe CWB (7,1 );
}
Function printit ()
{
If (confirm ('Are you sure you want to print? ')){
Pagesetup_null ();
Wb.exe CWB (6, 6)
}
}
</SCRIPT>
<Style type = "text/CSS" Media = print>
. Noprint {display: None}
</Style>
</Head>
<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" 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 ();">
</Body>
</Html>
----------------------------------------------------------------------
Note that an invalid error may occur during execution. The reason may be that your browser restricts the creation of active objects. You only need to cancel the restriction. The cancellation method is as follows:
Open Internet Options in your IE browser-security-Custom Level-Initialize ActiveX controls that are not marked as secure and set script run to enable