How to Disable the CTRL+P using javascript or Jquery?

后端 未结 11 1097
一生所求
一生所求 2020-12-31 06:17

Here I tried to disable the Ctrl+P but it doesn\'t get me alert and also it shows the print options

jQuery(document).bind(\"keyup keydo         


        
11条回答
  •  Happy的楠姐
    2020-12-31 06:32

    This Actually worked for me in chrome. I was pretty suprised.

    jQuery(document).bind("keyup keydown", function(e){
        if(e.ctrlKey && e.keyCode == 80){
             Print(); e.preventDefault();
        }
    });
    

    Where Print is a function I wrote that calls window.print(); It also works as a pure blocker if you disable Print();

    As noted here: https://stackoverflow.com/a/20121038/2102085

    window.print() will pause so you can add an onPrintFinish or onPrintBegin like this

    function Print(){
        onPrintBegin
        window.print();
        onPrintFinish(); 
    }
    

    (Again this is just chrome, but Peter has a downvoted solution below that claims the keycodes are different for ff and ie)

提交回复
热议问题