Prompt User To Print Page in JavaScript

- 1 minute read

Most modern browsers offer a built-in method of the window object that lets us prompt the user to print the current web page.

That method is called window.print, and it can be used like this:

const printPage = () => {
    window.print();
};

printPage();

// Note that calling this "printPage()" function is effectively the same as just calling "window.print()" directly.

All you have to do is just call window.print()!

But here’s one more trick, which attaches a print prompt to a clickable link using an HTML anchor tag:

<a href="javascript:window.print()">Print current web page</a> 

Link to this section Conclusion

Anyway, I hope you found this useful!

Happy page printing!