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 justevent.ctrlKey
because this already returnstrue
orfalse
– Patrick Oscity Commented Jul 7, 2012 at 10:09
3 Answers
Reset to default 2Have 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
评论列表(0条)