0

How to trigger a keypress event manually for a combination like Ctrl+P in angular/javascript?

I have tried using the window.print() method. But unfortunately, I have some css styles to be applied for the document to be printed in the @media print{} in css. The same style gets applied to the parent page as the one in print window.

Issue does not occur when clicking ctrl+p. The print window has separate styles applied, different from the original page in this case.

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
ps_dev
  • 69
  • 1
  • 9
  • So calling `window.print()` ignores the media rule, but pressing Ctrl+P doesn't? Can you create a [mre]? That almost sounds like a browser bug. –  Dec 27 '19 at 20:05
  • Below might help: https://stackoverflow.com/questions/3893397/how-to-trigger-key-combo-with-jquery https://stackoverflow.com/questions/16304538/trigger-ctrlp-printing-for-a-jquery-modal-box-through-keyboard Thanks. – Mehul Gayate Dec 27 '19 at 20:12
  • window.print() applies the css rule to both the print window as well as the page in background. But ctrl+p does not behave like that. It applies the css rule only to the print window. – ps_dev Dec 27 '19 at 20:18
  • @MehulGayate Im trying to figure out a javascript version for compination keypress. – ps_dev Dec 27 '19 at 20:21
  • 2
    This one: https://stackoverflow.com/questions/596481/is-it-possible-to-simulate-key-press-events-programmatically – Mehul Gayate Dec 27 '19 at 20:26

0 Answers0