javascript: capture CTRL+S

2019-04-05 2019-12-30 00:23:08 Javascript,native,EN

A cross-browser method to capture key combination CTRL+S with native JavaScript.

$(window).bind('keydown', function(event) {

    if (event.ctrlKey || event.metaKey) {

        switch (String.fromCharCode(event.which).toLowerCase()) {

            case 's':
                event.preventDefault();
                console.log('capture: CTRL+S');

                // do your stuff...

                break;
        }
    }
});

This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".