Ctrl+S preventDefault in Chrome

ctrl shortcuts
ctrl drink
ctrl sza
ctrl keys a-z
ctrl shift
ctrl meaning
ctrl z
ctrl c

I Want to catch Ctrl+S in Chrome, and prevent the default browser behavior to save the page. How?

(Just posting the question & answer as I was after this for a pretty long time and didn't find a solution)

As far as I can see, the secret sauce is, that Ctrl+S does NOT fire the keypress event, only the keydown event.

Using jQuery.hotkeys:

$(document).bind('keydown', 'ctrl+s', function(e) {
    e.preventDefault();
    alert('Ctrl+S');
    return false;
});

Only with jQuery:

$(document).bind('keydown', function(e) {
  if(e.ctrlKey && (e.which == 83)) {
    e.preventDefault();
    alert('Ctrl+S');
    return false;
  }
});

Edit 2012.12.17 - jQuery.hotkeys says

Hotkeys aren't tracked if you're inside of an input element (unless you explicitly bind the hotkey directly to the input). This helps to avoid conflict with normal user typing.

CTRL, Locked-In 🏅 This is the month we’ve been waiting for. Ctrl+Z: Redo the last operation Ctrl+Y, or Alt+Shift+Backspace ⇧ Shift+⌘ Cmd+Z: Ctrl+⇧ Shift+Z, or Ctrl+Y: Same as undo, when undo is exhausted, it redoes. Move the cursor after one or more undos, and further undos will be redos. Ctrl+r: Ctrl+⇧ Shift+Z: Cut the selection and store it in the clipboard: Ctrl+X, or ⇧ Shift+Del ⌘ Cmd+X

"Borrowed" from Overriding control+s (save functionality) in browser

document.addEventListener("keydown", function(e) {
  if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
    e.preventDefault();
    alert('captured');
  }
}, false);

Control key, In computing, a Control key Ctrl is a modifier key which, when pressed in conjunction with another key, performs a special operation (for example, Ctrl + C ); similar to the Shift key, the Control key rarely performs any function when pressed by itself. Ctrl keyboard shortcuts. Ctrl is used in keyboard shortcut keys, such as the three finger salute or Ctrl+Alt+Del. This key combination suggests pressing and holding down the Ctrl, Alt, and Del keyboard keys to open the Task Manager or reboot the computer. Below are the top uses for each of the keys when used in combination with the Ctrl key.

document.onkeydown = function (e) {
    e = e || window.event;//Get event
    if (e.ctrlKey) {
        var c = e.which || e.keyCode;//Get key code
        switch (c) {
            case 83://Block Ctrl+S
                e.preventDefault();     
                e.stopPropagation();
            break;
        }
    }
};
   

CTRL, CTRL. From Wikipedia, the free encyclopedia. CTRL or Ctrl may refer to several things: Channel Tunnel Rail Link, a high-speed railway line opened in the 2000s in Britain. Control key, an input button present on most computer keyboards. CTRL contains all you could ask for from a powdered meal replacement shake. Not only the stuff that you’ve heard of like proteins, healthy carbohydrates, fiber and healthy fats but even the things you might not normally pay attention to.. Read More

All in one solution to prevent data

// disable right click
$(function() {
    $(this).bind("contextmenu", function(e) {
        e.preventDefault();
    });
}); 

// Prevent F12      
$(document).keydown(function (event) {
    if (event.keyCode == 123) { // Prevent F12
        return false;
    } else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { // Prevent Ctrl+Shift+I        
        return false;
    }
});

//stop copy of content
function killCopy(e){
    return false
}
function reEnable(){
    return true
}
document.onselectstart=new Function ("return false")
    if (window.sidebar){
    document.onmousedown=killCopy
    document.onclick=reEnable
}

// prevent ctrl + s
$(document).bind('keydown', function(e) {
  if(e.ctrlKey && (e.which == 83)) {
    e.preventDefault();
    return false;
  }
});

What is Ctrl (Control)?, Ctrl. Updated: 06/30/2020 by Computer Hope. Short for control, Ctrl is a modifier key found on IBM compatible computer keyboards in the bottom left and right portion of the main keyboard. The picture is an example of what the Ctrl key may look like on your keyboard. In Ctrl, players try to dominate a cube by crawling over it with their colored bricks, preferably covering other players' bricks along the way. In more detail, you start with a 3×3×3 cube that has one block of each player color stuck into one of the cube's holes. (In a two-player game, each player controls two colors, but at the start of play they secretly choose one of those

CTRL Clothing, CTRL clothing and something (est 1995) is a fashion / skateboarding label from Helsinki Finland. Shop the collection online. Ctrl+C is a simple, lightweight and Cortana powered clipboard application for Universal Windows Platforms. If cut, copy & paste made your life easy, we just made it easier. There is data that needs to be used repetitively across applications. It is a pain to type them again and again.

CTRL Gene, GeneCards Summary for CTRL Gene. CTRL (Chymotrypsin Like) is a Protein Coding gene. Diseases associated with CTRL include Netherton Syndrome and � The Control or Ctrl key is normally found in the bottom left and right corners of any keyboard in a Windows computer. When used in combination with other keys, it can perform many useful functions

Drop CTRL Mechanical Keyboard | Price & Reviews, Free Shipping in USA | Drop exclusive product, price and reviews: Drop CTRL Mechanical Duration: 4:39 Posted: Apr 9, 2020 Ctrl + J. Open Downloads in a new tab (web UI) Ctrl + L. Select the URL in the address bar to edit. Ctrl + M. Mute current tab (toggle) Ctrl + N. Open a new window. Ctrl + O. Open a file from your computer in Edge. Ctrl + P. Print the current page. Ctrl + R. Reload the current page. Ctrl + S. Save the current page. Ctrl + Shift + B. Show or

Comments
  • possible duplicate of Overriding control+s (save functionality) in browser
  • jQuery.hotkeys does not seem to capture the event when a textarea or input field is focused.
  • @BrianM.Hunt very true thanks. Quoted docs as this is a documented "feature"
  • Tip: Do not use keyup, this will always trigger the save dialog first. Always go for keydown.
  • @KaiNoack Thanks so much! I've been stumped as to why my code wasn't working but no one else has pointed out this critical fact!