How to Print (to a real printer!) with Javascript

Short and sweet today – I never knew (well, never knew to look up) how to print a webpage with Javascript. Since you can do just about everything else with the window it’s not surprising, just never a use case I needed.

My “discovery” came while at work and trying to debug a component that wasn’t successfully pulling data from a Python-based API. Apparently my mind was still in Python mode and kept trying to print() instead of console.log() and it was causing the browser to try and print the screen. I’d close it out, go “huh” and the rerender would just pop the screen up again.

I found the offending line pretty quickly but was a bit annoyed it took me as long as I did, oh well!

Leave a comment