spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column91


Print Templates, Part II: TemplatePrinter

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Detecting the Print Action

The second page's LAYOUTRECT element has an event handler attached to it:

ONLAYOUTCOMPLETE="setTimeout('CheckIfPrintRequested()',
  100)"/>
</IE:DEVICERECT>

We want to call the function CheckIfPrintRequested() 100 milliseconds after the page is laid out. This is to ensure that the page won't be sent to the printer before the page's layout is complete and the event is consumed. A one millisecond interval would have been sufficient, but we want to play it safe.

The function CheckIfPrintRequested() gets its parameters from the dialogArguments variable. The dialogArguments is equal to the second parameter of the call to both showModalDialog() and showModelessDialog(). In this case, the executable printtemplates.exe calls the print template page, template2.html. This executable passes a few parameters as properties of a single object that is passed to the HTML page. The object is referenced in the print template as dialogArguments. Among its other properties, we use the __IE_PrintType to detect what the executable asked for. The executable determines its calls according to the user's requests through its Web page. When you click the Print with Prompt button, the executable sends a request to the Web page, setting __IE_PrintType to Prompt. The property __IE_PrintType may assume one of the following options: Prompt, Noprompt, and Preview. After checking the request, we call the proper function to handle it. We use a case statement for handling the various options:

invocations = 0;

function CheckIfPrintRequested() {
  invocations++;
  if (invocations > 1) return;
  switch (dialogArguments.__IE_PrintType) {
    case "Prompt":
      if (printer.showPrintDialog()) PrintPrep();
      break;
    case "NoPrompt":
      PrintPrep();
      break;
    case "Preview":
    default:
      break;
  }
}

Notice how we pop up the print dialog by calling one of the TEMPLATEPRINTER's methods, showPrintDialog(). Also notice the invocations variable. For some reason, the function CheckIfPrintRequested() is called twice when we request to print or preview the page. The variable invocations forces the switch statement to execute only once.

Next: How to print a document

http://www.internet.com

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: August 27, 2001
Revised: August 27, 2001

URL: http://www.webreference.com/js/column91/4.html