<link href="/path/to/print.css" media="print" rel="stylesheet" />Printing / notebook
Printing
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
@media print {
/* All your print styles go here */
#header,
#footer,
#nav {
display: none !important;
}
}window.addEventListener("afterprint", () => self.close);<button id="print_external">Print external page!</button>function setPrint() {
const closePrint = () => {
document.body.removeChild(this);
};
this.contentWindow.onbeforeunload = closePrint;
this.contentWindow.onafterprint = closePrint;
this.contentWindow.print();
}
document.getElementById("print_external").addEventListener("click", () => {
const hideFrame = document.createElement("iframe");
hideFrame.onload = setPrint;
hideFrame.style.display = "none"; // hide iframe
hideFrame.src = "external-page.html";
document.body.appendChild(hideFrame);
});