ES6 Page Printing

In several cases, it is required to place a button on a webpage that prints the content of the webpage by using the actual printer. JavaScript helps us in the implementation of printing a web page.

When the print function window.print() in JavaScript gets executed, then it prints the current webpage. We can directly call this function simply by using it in the onclick event.

Syntax

snippet
window.print();

Example

snippet
<html> 
  
<head>  

</head> 
  
<body> 
    <center> 
        <h1>Hello World :) :)</h1> 
        <h2>Welcome to javaTpoint</h2> 
        <h2>Click the following print button to see the changes</h2> 
        <input type = "button" value = "Print" onclick = "window.print()"/>
    </center> 
</body> 
  
</html>

Output

After the successful execution of the above code, you will get the following output:

ES6 Page Printing

When you click on the Print button, you will get the following screen:

ES6 Page Printing
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents