0

I have following code.

window.onkeypress = function(event) {

    if (event.charCode === 115 && event.ctrlKey) {
        event.preventDefault();
        // your code here....
        alert("'Save As' dialog suppressed!");
    }
};

That code works on Firefox, but in Chrome it doesn't work. Can you help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
veasna
  • 21
  • 1
  • 2

2 Answers2

2

You can't. Browsers don't expose (with good reason) the functionality to do this.

Don't annoy your users.

jdphenix
  • 15,022
  • 3
  • 41
  • 74
0

You can, and you may very well indeed want to do precisely that in order to NOT annoy your users with an annoying Save As Html prompt when they try to save something in your web app.

Say you're building your own T-Shirt Designer, a CMS app or whatever and you want to let your users press CTRL + S to save their changes... Very useful.

This example works fine - also in Chrome: https://stackoverflow.com/a/14180949/285853

PS: I realize that this post i 6 years old, so things might have changed in Chrome since then...

Miros
  • 527
  • 1
  • 3
  • 11