javascript - How to disable Ctrl + P for Chrome - Stack Overflow

One of mine application having custom button to print the customer invoice bill. The browser also havin

One of mine application having custom button to print the customer invoice bill. The browser also having default print option (Cntrl + P) to print the window content.

Initially, I resolved this problem by adding:

$(document).ready(function(){
    $(document).keydown(function(event) {
        if (event.ctrlKey==true && (event.which == '80') { //cntrl + p
            event.preventDefault();
        }
    });
 });

But I feel, this is not feasible solution for this. because am here binding this (keydown) event on document. so on each and every key press on application it firing this (keydown) event, and so which is very critical as per as the performance concern.

Is there any other-solution for this, so that i could disable the Cntrl + P (without binding event)?

Note: Important and good thing is our customer uses only Google Chrome browser to access this application.

One of mine application having custom button to print the customer invoice bill. The browser also having default print option (Cntrl + P) to print the window content.

Initially, I resolved this problem by adding:

$(document).ready(function(){
    $(document).keydown(function(event) {
        if (event.ctrlKey==true && (event.which == '80') { //cntrl + p
            event.preventDefault();
        }
    });
 });

But I feel, this is not feasible solution for this. because am here binding this (keydown) event on document. so on each and every key press on application it firing this (keydown) event, and so which is very critical as per as the performance concern.

Is there any other-solution for this, so that i could disable the Cntrl + P (without binding event)?

Note: Important and good thing is our customer uses only Google Chrome browser to access this application.

Share Improve this question edited Feb 6, 2023 at 23:03 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 7, 2012 at 9:44 Niks JainNiks Jain 1,6475 gold badges27 silver badges53 bronze badges 1
  • By the way: event.ctrlKey==true is exactly the same as just event.ctrlKey because this already returns true or false – Patrick Oscity Commented Jul 7, 2012 at 10:09
Add a ment  | 

3 Answers 3

Reset to default 2

Have you considered using this instead:

<link rel="alternate" media="print" href="alternativeUrlForPrint.ext" />

JavaScript is all about events, so you won't find a solution that doesn't rely on key events. Do you have actual performance issues? Every browser should be able to handle this.

Or, as a popular quote by Don Knuth puts it:

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil

As per my understanding, if some one have professional web based POS or business app, so for printing purpose you could use JZebra java applete, this would really resolve your all problems, because it doesn't have any dependencies on browser like print preview or browser's inbuild css etc..

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745319174a4622362.html

相关推荐

  • javascript - How to disable Ctrl + P for Chrome - Stack Overflow

    One of mine application having custom button to print the customer invoice bill. The browser also havin

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信