Launch Ctrl S or Ctrl P with a button

Now I know that you can listen to keystrokes (keydowns keyups, etc.), but I would like TRIGGER to press a key. As if the user presses CTRL + S to save.

Short question: is it possible to use Jquery to simultaneously run two keystrokes? I tried to look at it, but all I found was to talk about capturing keystrokes and not starting them, especially in two keystrokes at the same time.

Any ideas how to do this? If you could lead me to the right path, that would be very grateful.

+4
source share
2 answers

If you want to call your own handler code, you just have to put this code in a separate function and call the function normally.

If you want to run the default browser functionality, you must opt ​​out; this is not possible for security reasons. (Although you may be interested in window.print() )

+8
source

I don’t know if you can trigger keystrokes, but perhaps if you explain what exactly you are trying to achieve, can you find a solution?

For example, if you want to call ctrl-p to open the print dialog, you can do this using window.print();

If you want to run actions in your own code, you can simply call the code directly, rather than trigger a keystroke.

I don’t think there is a way to call the file | save as ( ctrl-s ) using JavaScript.

+3
source

All Articles