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
May be interested
- How to print multiple Word pages in one sheet of paperby default, when printing, you print a page of word documents on a sheet of paper. but for the needs and purposes of many people, to save or fit the purpose of using the prints, you want to print many pages of word in a single sheet of paper.
- How to Enable JavaScriptthis article shows you how to enable javascript in your computer's browser, which allows the browser to load and display certain things--such as videos or animations--on some web pages. you can enable javascript if you're using chrome on desktop and android, safari on mac and iphone, firefox on desktop, and microsoft edge and internet explorer on windows. once enabled, you will fix the error and no longer see javascript-related messages.
- How to Print Double Sided on a Macthis wikihow teaches you how to print double-sided pages on a mac computer. in order to print double-sided pages automatically, you must have a printer that is compatible with duplex printing. if your printer is not capable of printing...
- How to delete, cancel print orders on Canon, HP, Brother printers... immediatelyduring use, sometimes our printer has problems printing continuously or simply we mistakenly print dozens of pages. so how to cancel a print order on the computer?
- What is JavaScript? Can the Internet exist without JavaScript?not everyone knows what javascript is and how it works. the long and fascinating development history of javascript as well as what we can do with javascript is still unknown.
- How to print multiple pages on one sheet of paper in Word 2010, 2013you can print from 2 to 16 pages on a sheet of a4 paper, this technique is used when printing small documents, helping to reduce printing costs. how to do it will be shared by free download right after this.
- How to Enable Cookies and JavaScriptthis article shows you how to enable cookies and javascript in your web browser. cookies are pieces of data from visited websites that browsers store to make re-visiting and using those websites quicker and more personal. javascript is a computer language that allows browsers to load and display some eye-catching things on web pages. remember that if left on by default, javascript is usually enabled on most browsers.
- How to cancel the print job immediatelyyou ordered a print job of a document that was dozens of hundreds of pages long, but realized that you printed the wrong document and wanted to quickly cancel the print job. this article shows you how to cancel print jobs for your reference.
- What is Currying in Javascript? How to use Currying in JavaScriptthe currying feature in javascript can help you keep your code tidy and give you a new way of seeing how functions work. currying is ideal when you want to break complex logic into smaller, manageable, and self-contained pieces of code.
- Things to know about 'this' in JavaScriptare you having trouble understanding the keyword 'this' in javascript ? then please read what you need to know about 'this' in javascript below.