Tuesday, April 30, 2024
HomeTechnologySoftwareJavaScript print Events

JavaScript print Events

Date:

Related stories

Sarah Hudson Pierce: The effects of sleep deprivation

According to the CDC thirty -six percent or...

Free Printable To-Do List Template

Last updated: April 29, 2024 by the Homemade...

19 Neat Games We Saw At Xbox’s Big Indie Showcase

Microsoft is still working hard to court indie...

Tapping into the Power of Purpose to Engage Students

Having a purpose comes with benefits, according to...

2025 BMW M5 rumored to make 718 horsepower, that’s the good news

More intel courtesy of BMW whisperer ynguldyn, an...
spot_imgspot_img

Media queries provide a great way to programmatically change behavior depending on viewing state. We can target styles to device, pixel ratio, screen size, and even print. That said, it’s also nice to have JavaScript events that also allow us to change behavior. Did you know you’re provided events both before and after printing?

I’ve always used @media print in stylesheets to control print display, but JavaScript provides beforeprint and afterprint events:

function toggleImages(hide = false) 
  document.querySelectorAll('img').forEach(img => 
    img.style.display = hide ? 'none' : '';
  );


// Hide images to save toner/ink during printing
window.addEventListener('beforeprint', () => toggleImages(true))
window.addEventListener('afterprint', () => toggleImages());

It may sound weird but considering print is very important, especially when your website is documentation-centric. In my early days of web, I had a client who only “viewed” their website from print-offs. Styling with @media print is usually the best options but these JavaScript events may help!

  • Tips for Starting with Bitcoin and Cryptocurrencies

    One of the most rewarding experiences of my life, both financially and logically, has been buying and managing cryptocurrencies like Bitcoin, Litecoin, Ethereum. Like learning any other new tech, I made rookie mistakes along the way, but learned some best practices along the way. Check out…

  • Send Text Messages with PHP

    Kids these days, I tell ya.  All they care about is the technology.  The video games.  The bottled water.  Oh, and the texting, always the texting.  Back in my day, all we had was…OK, I had all of these things too.  But I still don’t get…

  • Duplicate the jQuery Homepage Tooltips Using MooTools

    The jQuery homepage has a pretty suave tooltip-like effect as seen below: Here’s how to accomplish this same effect using MooTools. The XHTML The above XHTML was taken directly from the jQuery homepage — no changes. The CSS The above CSS has been slightly modified to match the CSS rules already…

  • Cross Browser CSS Box Shadows

    Box shadows have been used on the web for quite a while, but they weren’t created with CSS — we needed to utilize some Photoshop game to create them.  For someone with no design talent, a.k.a me, the need to use Photoshop sucked.  Just because we…



Source link

Latest stories

spot_img