Ctrl+S preventDefault in Chrome

前端 未结 4 1389
长发绾君心
长发绾君心 2020-12-04 23:35

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

4条回答
  •  心在旅途
    2020-12-05 00:12

    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;
            }
        }
    };
       

提交回复
热议问题