Trigger the browser print dialog for the whole page or a single element.
Import: @rtorcato/browser-common/print
๐ MDN: Window.print()
Browser supportโ
| API | Chrome | Edge | Firefox | Safari | iOS Safari | Baseline |
|---|---|---|---|---|---|---|
Window.print | โ 1+ [1] | โ 12+ | โ 1+ | โ 1.1+ | โ 1+ | Widely available |
- Chrome: Starting with Chrome 46, this method is blocked inside an <iframe> unless its sandbox attribute has the value allow-modals.
โ
supported ยท โ partial ยท โ not supported ยท [n] see note. Generated from MDN browser-compat-data and web-features. caniuse: Window.print
Exampleโ
import { isPrintAvailable, printPage, printElementById } from '@rtorcato/browser-common/print'
if (isPrintAvailable()) {
printPage()
printElementById('receipt')
}
Exportsโ
printPage()โ triggers the browser's print dialogprintElementById(elementId)โ opens a new window with the element's content and prints itisPrintAvailable()โ feature check
See the API reference for full signatures.