Skip to content

Instantly share code, notes, and snippets.

@mothdotmonster
Last active November 11, 2025 00:55
Show Gist options
  • Select an option

  • Save mothdotmonster/9aa9da19f8cb7eb7ca053dd5f9ae618a to your computer and use it in GitHub Desktop.

Select an option

Save mothdotmonster/9aa9da19f8cb7eb7ca053dd5f9ae618a to your computer and use it in GitHub Desktop.
makes the print() function accept arguments as it should
function print(object) {
let frame = document.createElement("iframe")
document.body.appendChild(frame)
frame.style.display = "none"
frame.srcdoc = new Option(JSON.stringify(object, null, 1)).innerHTML
frame.onload = () => {frame.contentWindow.print()}
}
function print(o){let f=document.createElement("iframe");document.body.appendChild(f);f.style.display="none";f.srcdoc=new Option(JSON.stringify(o,null,1)).innerHTML;f.onload=()=>{f.contentWindow.print()}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment