Print pages in JavaScript
Many times you will love to put a button on your website to print the content of that page through a printer. JavaScript helps you perform this function by using the print function of the window object.
The window.print () function in JavaScript prints the current page when executed. You can call this function directly using the onclick event as in the following example:
For example
Try the following example:
Result
Follow the above method to see the results
Although it serves the purpose of printing, it is not the recommended way to use. A friendly printer page is actually a page with text, no images, graphics or advertising.
You can create a friendly page printer in the following ways:
Create a copy of the page and remove the excess text, graphics, and then connect to that friendly page printer. You check the following example: Example.
If you don't want to keep an extra copy of the page, you can mark printable text using the same comments as: . and then you can use PERL or any other script in the background to filter printable text and display it for the final print job. You use this method to provide print media to visitors. You check for example: For example.
How to print a page
If you don't see the media on a web page, you can use the browser's standard toolbar to print the site. Follow the following link:
File → Print → Click OK button .
According to Tutorialspoint
Previous article: Void keyword in JavaScript
Next article: Objects in JavaScript
You should read it
- Syntax of JavaScript
- What is JavaScript? Can the Internet exist without JavaScript?
- Learn about ES6 in Javascript
- What is JavaScript?
- Udemy's top 5 JavaScript courses
- How to Turn on JavaScript
- How to Enable JavaScript
- What is Currying in Javascript? How to use Currying in JavaScript
- Things to know about 'this' in JavaScript
- ! = and! == What is the difference in JavaScript?
- Top site with many good JavaScript exercises to practice
- Document Object Model (DOM) in JavaScript
May be interested
Objects in JavaScript
Tutorial for creating slideshows in JavaScript with 3 easy steps
7 Framework JavaScript for mobile application development
Introduction to 2D Array - 2-dimensional array in JavaScript
12 extremely useful tricks for JavaScript programmers
Arrays and objects in JavaScript are like stories and newspapers!