Given an HTML document and the task is to design a button that would pop-up a print dialog box. We are going to use JavaScript to do the assigned task:
- Approach::
- Add a button which links to a JavaScript Function.
- Inside the JavaScript Function, use the JavaScript default function to call the print dialog box
Syntax:
window.print
Example:
<!DOCTYPE html><html><head><title>create a pop-up to printdialog box using JavaScript</title></head><body><center><h1style="color:green">GeeksforGeeks</h1><script>function printPopUp() {alert("Pop-up dialog-box")window.print();}</script><buttononclick="printPopUp()">Print</button></center></body></html>chevron_rightfilter_noneOutput:
Before:

After:

- Approach::
- Use DOM onload Event in body tag.
- Use window alert method for pop-up dialog-box and window.print to print the document.
Example:
<!DOCTYPE html><html><head><title>create a pop-up to printdialog box using JavaScript</title></head><bodyonload="alert('Pop-up dialog-box');window.print();"><center><h1style="color:green">GeeksforGeeks</h1>create a pop-up to print dialog box using JavaScript</center></body></html>chevron_rightfilter_noneOutput:

- Approach::
- Use <a> href attribute to hyperlink text.
- Use window alert method for pop-up dialog-box and window.print to print the document.
Example:
<!DOCTYPE html><html><head><title>create a pop-up to printdialog box using JavaScript</title></head><body><center><h1style="color:green">GeeksforGeeks</h1><ahref="javascript:alert('Pop-up dialog-box');window.print();">Click Me</a></center></body></html>chevron_rightfilter_noneOutput:
Before:

After:

Recommended Posts:
- How to create a dialog box or window in HTML ?
- What are the types of Popup box available in JavaScript ?
- How to close a dialog box in windows?
- How to display confirmation dialog when clicking an <a> link using JavaScript / jQuery ?
- How to change Input box borders after filling the box using JavaScript ?
- How to open popup using Angular and Bootstrap ?
- How to fit the image into modal popup using Bootstrap?
- Difference between alert box and confirmation box in JavaScript
- How to center a popup window on screen?
- Semantic-UI | Popup
- How to use the Magnific Popup jQuery plugin?
- How to display popup message when logged out user try to vote ?
- How to refresh parent page on closing a popup ?
- HTML5 | <dialog> Tag
- HTML | DOM Dialog Object
- HTML | dialog open Attribute
- ES6 | Dialog Boxes
- JQueryUI | dialog
- How to disable a button in jQuery dialog from a function ?
- Python - Tkinter Choose color Dialog
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


