Javascript print overviewThe print() method provides a scripted way of sending the window or a frame from a frameset to the printer.In all cases,the Print dialog box appears for the user to make the typical printer choices when printing manually.This presents a rogue print() command from tying up a printer without the user's permission | NN4 | NN5 | NN5 | IE5 | IE6 | Compatibility | NO | YES | YES | YES | YES |
Using window.print() to print a documentThe Javascript print() function performs the same operation as the IE or NN print option .The Javascript print function will send the contents of the page to the user's printer.See below example code: <form> <input type="button" value="Print This Page" onClick="window.print()" /> </form> If you click print() button your computer will handle the printing functions.
Onload Javascript print ()If you want to be annoying, off of just about any Event Handler like this, adding onLoad will force a print request when the page loads: onLoad="window.print()"
Javascript print link example <a href="javascript:window.print()">Print The Page</a>
Using window.print() to print a frame documentIn IE5,the print dialog box gives the user the chocie of printing hust frame or all of the frames.Make sure that the print() method is invoked for the desired frame when you want only that frame to print.The browser defaults to printing just that frame function printFrames(n){ parent.frames[n++].print() if(n<parent.frames.length) { setTimeout("printFrames("+n+")",5000) } } Advice about Javascript print function- You should always make a Page which can be Printed
- You should make the Page Printer-Friendly. To make a page printer friendly, simply make a copy of the page and leave out unwanted text and graphics, then link to that printer friendly page from the original.
- You should allow the User to Choose to Print
|