Webbrowser is a browser control built in IE, which does not need to be downloaded by users. This document discusses the technical content of the webbrowser control of ie6.0. Other versions of IE should also support. Related Technical requirements include generation of printed documents, page settings, and implementation of printing operations. This article takes ASP as an example, but it can be easily transplanted to other web technologies.
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 );
3. Set printing, generate printing data, preview printing, and print printing.
Print settings, print data generation, print preview, and print I usually do this, if the query result is in. ASP, then in. ASP contains three buttons: Print setting, print preview, and print.
Click the print Settings button to execute webbrowser1.execwb () in JS to open the print settings window.
Click the print preview button to open B. asp, generate a new print data in B. asp, and then automatically execute webbrowser1.execwb () in B. asp to open the user preview interface.
Click the print button to enable B. asp. generate a new print data in B. asp, and then automatically execute webbrowser1.execwb (6, 1) in B. asp to automatically print the data.
Iv. Code
A. The program for ASP to call data is not provided. The code for only a few buttons is provided:
<Input type = "button" name = "mprint" value = "print" onclick = "exeprint ();">
<Input type = "button" name = "mpreview" value = "print preview" onclick = "exepreview ();">
<Input type = "button" name = "msetting" value = "Print setting" onclick = "exesetting ();">
<Object ID = 'webbrowser 'width = 0 Height = 0 classid = 'clsid: 8856f961-340a-11d0-a96b-00c04fd705a2 '> </Object>
<Script language = 'javascript '>
Function exeprint ()
{
Liu = Window. Open ('B. asp? Do = 1', '_ blank', 'left = 2000, Top = 2000, fullscreen = 3 ');
}
Function exepreview ()
{
Window. Open ('B. asp? Do = 2', '_ blank', 'left = 2000, Top = 2000, fullscreen = 3 ');
}
Function exesetting ()
{
Webbrowser. execwb (8, 1 );
}
</SCRIPT>
Printing the set code in the code is simple and easy to understand. The print preview and print button must tell B. asp whether the print or print preview is to be executed. In addition, the query string must be passed over. Of course, Web experts can try other methods to avoid repeated re-debugging of data on the server. Of course, beginners can only query multiple times to solve the problem of printing at the cost of performance.
In this example, if a. asp opens B. asp by passing a query string, data is reloaded in B. asp. After loading the data here, you need to know the number of pagesize entries to be displayed on the webpage ). Each time pagesize is displayed, A <P style = 'page-break-before: Always; '> statement is equivalent to a paging character, that is, when this paging character is encountered during print or preview, the page is forcibly paged. Generally, we can:
<Table>
???
</Table>
<P style = 'page-break-before: Always; '>
<Table>
???
</Table>
<P style = 'page-break-before: Always; '>
......
<Table>
???
</Table>
<P style = 'page-break-before: Always; '>
After the data is displayed, preview or print the data separately based on the user's command (the do parameter value is determined.
For preview, run the following code:
Webbrowser. execwb (7,1 );
Window. Opener = NULL;
Window. Close ();
If it is printed, run the following command:
Webbrowser. execwb (6, 1 );
Window. Opener = NULL;
Window. Close ();