Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Listen when ctrl + p is pressed to bring printApi page...
- var controlPressed = false;
- //Listen for Command + P in Mac Browsers...
- var commandPressed = false;
- console.log(controlPressed);
- $(window).bind('keydown', function(event){
- var key = event.keyCode || event.charCode || 0;
- if (key == 91) {
- commandPressed = true;
- }
- if (key == 93) {
- commandPressed = true;
- }
- if (key == 17) {
- controlPressed = true;
- }
- if(key == 80 && controlPressed){
- event.preventDefault();
- if (/Trident/.test(navigator.userAgent)) {
- alert('Click OK to go to print page.');
- }
- var printURL = document.URL.replace('show', 'print');
- window.location.href = printURL;
- controlPressed = false;
- return false;
- }
- if(key == 80 && commandPressed){
- event.preventDefault();
- if (/Trident/.test(navigator.userAgent)) {
- alert('Click OK to go to print page.');
- }
- var printURL = document.URL.replace('show', 'print');
- window.location.href = printURL;
- controlPressed = false;
- return false;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement