Try OpenEdge Now
skip to main content
Developing WebSpeed Applications
Using JavaScript with WebSpeed : Some JavaScript examples : Printing from an HTML page

Printing from an HTML page

This example shows how a Web page can print itself after it finishes loading in the Web browser:
<BODY onLoad="window.print()">
This example will pop up the printer dialog box when it's loaded into the
browser. The intention of this example is for WebSpeed users to create
applications that can print HTML documents without browser interaction.
The next example shows how you can print a portion of a page dynamically. First, you must set up two frames, one that takes up the entire browser window and another that is hidden, as shown:
/* startup.w */
  <FRAME ID="appFrame" SRC="myApp.w" SCROLLING="no">
  <FRAME ID="jsFrame" SRC="empty.html" SCROLLING="no"
The appFrame contains the application. The jsFrame is used for communicating with the server and for running applications like printing.
The following shows the filePrint() function in the simplified myApp.w code fragment:
/* myApp.w fragment */
function filePrint() {
  var newPage = '<PRE>' + document.form1.elements["textarea0"].value;
The filePrint() function copies the value of a <TEXTAREA> field named textarea0 to the hidden frame with a <PRE> prefix. Focus is moved to that frame and then it is printed. If you eliminate the <PRE> prefix, the browser renders the context of textarea0 before it is printed.