Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda