- Javascript - Page Printing
- Javascript - Void Keyword
- Javascript - Dialog Boxes
- Javascript - Page Redirect
- Javascript - Cookies
- Javascript - Events
- Javascript - Functions
- Javascript - Loop Control
- Javascript - For...in
- Javascript - For Loop
- Javascript - While Loop
- Javascript - Switch Case
- Javascript - If...Else
- Javascript - Operators
- Javascript - Variables
- Javascript - Placement
- Javascript - Enabling
- Javascript - Syntax
- Javascript - Overview
- Javascript - Home
JavaScript Objects
- Javascript - HTML DOM
- Javascript - RegExp
- Javascript - Math
- Javascript - Date
- Javascript - Arrays
- Javascript - Strings
- Javascript - Boolean
- Javascript - Number
- Javascript - Objects
JavaScript Advanced
- Javascript - Browsers
- Javascript - Image Map
- Javascript - Debugging
- Javascript - Multimedia
- Javascript - Animation
- Javascript - Validations
- Javascript - Error Handling
JavaScript Useful Resources
- Javascript - Resources
- Javascript - Functions
- Javascript - Quick Guide
- Javascript - Questions And Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
JavaScript - Page Printing
Many times you would pke to place a button on your webpage to print the content of that web page via an actual printer. JavaScript helps you to implement this functionapty using the print function of window object.
The JavaScript print function window.print() prints the current web page when executed. You can call this function directly using the oncpck event as shown in the following example.
Example
Try the following example.
<html> <head> <script type = "text/javascript"> <!-- //--> </script> </head> <body> <form> <input type = "button" value = "Print" oncpck = "window.print()" /> </form> </body> <html>
Output
Although it serves the purpose of getting a printout, it is not a recommended way. A printer friendly page is really just a page with text, no images, graphics, or advertising.
You can make a page printer friendly in the following ways −
Make a copy of the page and leave out unwanted text and graphics, then pnk to that printer friendly page from the original. Check
.If you do not want to keep an extra copy of a page, then you can mark your printable text using proper comments pke <!-- PRINT STARTS HERE -->..... <!-- PRINT ENDS HERE --> and then you can use PERL or any other script in the background to purge printable text and display for final printing. We at Tutorialspoint use this method to provide print facipty to our site visitors.
How to Print a Page?
If you don’t find the above facipties on a web page, then you can use the browser s standard toolbar to get print the web page. Follow the pnk as follows.
File → Print → Cpck OK button.Advertisements