Sunday, January 29, 2023
HomeSoftware DevelopmentJavaScript print Occasions

JavaScript print Occasions

Media queries present an effective way to programmatically change habits relying on viewing state. We are able to goal types to gadget, pixel ratio, display screen measurement, and even print. That stated, it is also good to have JavaScript occasions that additionally permit us to vary habits. Do you know you are offered occasions each earlier than and after printing?

I’ve at all times used @media print in stylesheets to regulate print show, however JavaScript offers beforeprint and afterprint occasions:

perform toggleImages(cover = false) {
  doc.querySelectorAll('img').forEach(img => { = cover ? 'none' : '';

// Disguise photographs to avoid wasting toner/ink throughout printing
window.addEventListener('beforeprint', () => toggleImages(true))
window.addEventListener('afterprint', () => toggleImages());

It might sound bizarre however contemplating print is essential, particularly when your web site is documentation-centric. In my early days of net, I had a shopper who solely “seen” their web site from print-offs. Styling with @media print is often the very best choices however these JavaScript occasions might assist!

  • Vibration API

    Lots of the new APIs offered to us by browser distributors are extra focused towards the cellular consumer than the desktop consumer.  A type of easy APIs the Vibration API.  The Vibration API permits builders to direct the gadget, utilizing JavaScript, to vibrate in…

  • Create Spinning Rays with CSS3: Revisited
  • MooTools Flashlight Effect
  • The Simple Intro to SVG Animation

    This text serves as a primary step towards mastering SVG component animation. Included inside are hyperlinks to key assets for diving deeper, so bookmark this web page and refer again to it all through your journey towards SVG mastery. An SVG component is a particular sort of DOM component…



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments