Home > Domino Tips > Developer > JavaScript > Create a Web print button that omits certain items on the page
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

Create a Web print button that omits certain items on the page


Dan Herman
12.17.2001
Rating: -4.06- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Ever want to have a print button on your Web page that only prints certain parts of the page and omits other parts? This can easily be done in Notes with a Hide/When for printing. Here's a way to do it with javascript on the Web.



Code

Simply enclose the parts of the page you wish not to print with the following:

<div id="divNoPrint1">
Dont print this line
</div>

Of course the "Dont print this line" is my sample text, and the <div> elements need to be pass-thru HTML.

As you add multiple DIV statements to omit other parts of your page increment the div number (ie "divNoPrint2" and "divNoPrint3" etc.. in place of the divNoPrint1 example above)

Then add the following function to JS Header of the form.

function printPage() {
var numDivs = 20;
for(i=1;i<numDivs;i++) {
  if(document.all['divNoPrint'+i]){
    document.all['divNoPrint'+i].style.display = 'none'; }
 }
 window.print();
for(i=1;i<numDivs;i++) {
  if(document.all['divNoPrint'+i]){
    document.all['divNoPrint'+i].style.display = ''; }
 } 
}

This function above only supports 20 items, but of course you can change the divNums variable to be a higher number if necessary.

Then add a print button to your page, form, or view template as such:

<div id="divNoPrint3" align=right><a href="#" 
onClick="printPage();"><img src="/icons/actn147.gif" border=0 
alt="Print page"></a></div>

Of course make sure the above code for the print button is pass-thru HTML. (And note how it is using the name "divNoPrint3" so that it wont be printed.)

And thats it. When the print button is clicked the page will appear to jump for a second (hiding the sections that are not to be printed) and then the print dialog box will come up and the page will return to normal.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
JavaScript
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Prevent errors on iFramed pages with JavaScript
How to add keyboard functionality for Lotus Notes documents
Validate Lotus Notes Domino fields using JavaScript
How to support Flash objects in any Web browser for a Lotus Notes Domino application
How to validate Lotus Notes forms on a Domino server without losing entered data
Ajax code equivalent of the @DBColumn formula for Lotus Notes
A bevy of Notes/Domino development tips

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts