Print webpage using JavaScript

In this tutorial I am going to show you how to print webpage using Javascript. To do this we will use window.print() Javascript method. Let’s have a look at the live demo.

STEP 1: Print webpage using JavaScript

Write down the following HTML code in the body section of your webpage.

<button onclick="print()">Print this page</button>

STEP 2: Print webpage using JavaScript

Now, Write down the following Javascript code in the body section below the HTML code you wrote before.

<script type="text/javascript">
function print() {
    window.print();
}
</script>

Books you should read :

[amazon template=findsourcecode&asin=1497408180][amazon template=findsourcecode&asin=0596805527]

Post Tagged with , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

12 + nine =

This site uses Akismet to reduce spam. Learn how your comment data is processed.