WebSpeed
Product Update Bulletin


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. 
</BODY> 

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:

/* startup.w */ 
<FRAMESET FRAMEBORDER=1 COLS="100%,*"> 
  <FRAME ID="appFrame" SRC="myApp.w" SCROLLING="no"> 
  <FRAME ID="jsFrame" SRC="empty.html" SCROLLING="no"  
  NORESIZE FRAMEBORDER=0 MARGINHEIGHT=0 MARGINWIDTH=0> 
</FRAMESET> 

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 */
<SCRIPT LANGUAGE="JavaScript">
function filePrint() {
var newPage = '<PRE>' + document.form1.elements["textarea0"].value;
  parent.jsFrame.document.write(newPage);
  parent.jsFrame.document.close();
  parent.jsFrame.focus();
  parent.jsFrame.print();
}
</SCRIPT> 

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.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095