JavaScript print() method

The Print() method in JavaScript opens the print dialog to print the current window or document. This method will support Browsers like Edge, Internet Explorer, Google Chrome, Firefox, Opera, Safari, etc.

There are no parameters or return values.

Syntax:

window.print()

Example:

<html>  
<head>  
<title>  
Use print() method in JavaScript  
</title>  
<script type = "text/ javascript">  
  
<!-- 
 
// -->  
</script>  
</head>  
<body>  
<h2>  print() method </h2>  
<p>  
    The "print()" method displays the current window contents, as the name suggests. When we call the "print()" method, a print dialog box appears, allowing the user or programmer to select the best option for printing the current content of the window. </p>  <br>

<form>  
  
<!-- When a user click on the print button, the onclick function calls the window.print() method to print the currently visible content in the window screen. -->   
<input type = "button" value = "Print" onclick = "window.print()" />  
</form>  
</body>  
</html>

When we execute the above programming code on any browser, it displays the below image:

Output:

In the above image, there is a Print button. Now we click on the Print button, it opens a print dialog box with the current visual content of the window screen, as shown below.

Leave a Comment

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

Scroll to Top