---
title: "Why are the use of page printing in JS?"  
description: "Why are the use of page printing in JS?"  
author: "Ravi Vishwakarma"  
published: 2021-07-19  
canonical: https://answers.mindstick.com/qa/93758/why-are-the-use-of-page-printing-in-js  
category: "web application"  
tags: ["javascript", "web application development", "web development"]  
reading_time: 2 minutes  

---

# Why are the use of page printing in JS?

Why are the use of [page](https://www.mindstick.com/articles/85722/common-on-page-seo-mistake-how-to-fix) [printing](https://www.mindstick.com/blog/63804/5-ways-you-can-use-printing-in-your-marketing-strategy) in JS?

## Answers

### Answer by Ethan Karla

Page print in JavaScript is a simple code in JavaScript used to print the content of the web pages. • The print() method prints the contents of the current window. • It basically opens Print dialog box which lets you choose between various printing options.

```
Syntax
 window.print();
```

```
Exapmle
 <!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title>Print page</title>
    <style>
        body {
            background-color:red;
            text-align:center;
        }
    </style>
</head>
<body>
    <button name='btn' id='btn' onclick='window.print()' >Print this page</button>
</body>
</html>
```

\

### Answer by Ravi Misra

Many times you would like 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 functionality using the **print** function of the **window** object.

The JavaScript print function **window.print()** prints the current web page when executed. You can call this function directly using the **onclick** event as shown in the following example.

```html
<html>
   <head>
      <script type = 'text/javascript'>
         <!--
         //-->
      </script>
   </head>

   <body>
      <form>
         <input type = 'button' value = 'Print' onclick = 'window.print()' />
      </form>
   </body>
<html>
```


---

Original Source: https://answers.mindstick.com/qa/93758/why-are-the-use-of-page-printing-in-js

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
