Open In App

How to print a page using jQuery ?

The task is to print a page using jQuery by calling a window.print method when the user clicks on a Button. The window.print() method is sent to open the Print Dialog Box to print the current document. It does not have any parameter value. 

Example:



HTML Code:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        How to. print a page using jQuery.?
    </title>
</head>
  
<body>
    <center>
        <h1>Hello GeeksForGeeks Users</h1>
  
        <h3>
            How to. print a page using jQuery.?
        </h3>
  
        <Button id="sudo" onclick=
            "print_current_page()" />
            Print!
        </button>
    </center>
</body>
  
</html>

jQuery Code:



$('#sudo).click(function(){
    window.print();
    return false;
});

Output:

Before Clicking On Button:

After Clicking On Button:

Supported Browsers:

Article Tags :