TenVolt
                          Tech Notes
JavaScript > Printing articles:

 • Adding a Print link or button to your page

Return to index of articles

Adding a Print link or button to your page

Category: JavaScript
Category: Printing

Background You may want to provide a Print button or link to make it easier for your visitors to print the current page, especially in a frames-based site. Netscape and Internet Explorer both provide this functionality through the Javascript window.print() function. Suppress The Print Dialog Box Even more handy is the ability to print without any user intervention (the print dialog box is not shown) in Internet Explorer versions 5.0 and newer. The code below shows a cross-browser compatible "print" link. Just copy this code into a new document and save it with a .HTM extension. When you click the Print link in Netscape, the print dialog will pop up; in Internet Explorer 5.0 or greater, the print dialog will be suppressed, meaning the page will be printed in just one click. Code >pre< >html< >head< >title/title< >/head<>body< >OBJECT ID="IEControl" WIDTH=0 HEIGHT=0 CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"< >/OBJECT< >script language="JavaScript"< >!-- VBS = false; //--< >/script< >script language="VBScript" type="text/VBScript"< >!-- VBS = true function printThis call IEControl.ExecWB(6, -1) ' change the -1 to 1 if you want the print dialog to appear end function //--< >/script< >script language="JavaScript"< function printIt() { if (VBS) { printthis(); } else { window.print(); } ; } >/script< Here is some text on the page. If you would like to print this text with NO print dialog in IE5+_then please>BR< >a href="#" onClick="javascript:printIt();return false;"/a< >/body< >/html< >/code< Example Click here to print this page. Related Tip If you are doing this so that you can connect to an Access database, make sure the directory is writeable, otherwise you will not be able to modify or delete any records in your database. To make the appropriate directory writeable, you will most likely have to ask your ISP to do it for you.

9/1/2002

 TuneVault
 Music & MP3's
 10v Calendar
 Online & Easy
 Craigger
 Various & Misc.
 RetroVault
 Toys Toys Toys!
   

All contents ©2003 Ten Volt Consulting. All rights reserved.
Unauthorized duplication or use is a violation of applicable laws.
Webmaster Contact