Why are the use of page printing in JS?

0 votes
28 views
Ravi Vishwakarma asked 13 days ago in Web Application by Ravi Vishwakarma

Why are the use of page printing in JS?    

1 Answer

0 votes
Ethan Karla answered 10 days ago 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>