Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Can I prevent ctrl + shift + p system print dialog on windows in the browser?

I would like to use the key combination ctrl + shift + p to open a command palette similar to how one opens on https://vscode.dev. This appears to work fine in browsers on MacOS, however when I try to do the same on windows it will open a system print dialog.

I have tried to add an event listener for 'beforeprint' but I don't believe it is cancellable.

window.addEventListener('beforeprint', (event) => {
   event.preventDefault();
   event.stopPropagation();
});

I'm trying to prevent the print dialog in this handler for the keybind

document.addEventListener('keydown', (event) => {
   if (event.key === 'p' && event.shiftKey && (event.ctrlKey || event.metaKey)) {
      // Prevent browser print dialog
      event.preventDefault();
      // Prevent dev tools command palette from opening
      event.stopPropagation();
      
      // Do logic here
   }
});

This handler works seems to work fine on MacOS safari and chrome but I cannot replicate the behavior on Windows where it opens the system print dialog.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I was able to resolve this issue by switching my check for event.key === 'p' to event.keyCode === 80. I did not have any need for the 'beforePrint' handler.

document.addEventListener('keydown', (event) => {
   if (event.keyCode === 80 && event.shiftKey && (event.ctrlKey || event.metaKey)) {
      // Prevent browser print dialog
      event.preventDefault();
      // Prevent dev tools command palette from opening
      event.stopPropagation();
      
      // Do logic here
   }
});
about 4 years ago · Juan Pablo Isaza Report

0

If you are using/can use jQuery:

$(document).bind("keyup keydown", function(e) {
  if (e.ctrlKey && e.keyCode == 80) {
    alert("Do what ever you want here.")
    return false; // Stops print  
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

If you run it here, it won't work. Try running it on codepen or somewhere else.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!