Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Listen when ctrl + p is pressed to bring printApi page...
  2.     var controlPressed = false;
  3.  
  4.     //Listen for Command + P in Mac Browsers...
  5.     var commandPressed = false;
  6.     console.log(controlPressed);
  7.     $(window).bind('keydown', function(event){
  8.         var key = event.keyCode || event.charCode || 0;
  9.         if (key == 91) {
  10.             commandPressed = true;
  11.         }
  12.  
  13.         if (key == 93) {
  14.             commandPressed = true;
  15.         }
  16.  
  17.         if (key == 17) {
  18.             controlPressed = true;
  19.         }
  20.  
  21.         if(key == 80 && controlPressed){
  22.             event.preventDefault();
  23.             if (/Trident/.test(navigator.userAgent)) {
  24.                 alert('Click OK to go to print page.');
  25.             }
  26.             var printURL = document.URL.replace('show', 'print');
  27.             window.location.href = printURL;
  28.             controlPressed = false;
  29.             return false;
  30.         }
  31.  
  32.         if(key == 80 && commandPressed){
  33.             event.preventDefault();
  34.             if (/Trident/.test(navigator.userAgent)) {
  35.                 alert('Click OK to go to print page.');
  36.             }
  37.             var printURL = document.URL.replace('show', 'print');
  38.             window.location.href = printURL;
  39.             controlPressed = false;
  40.             return false;
  41.         }
  42.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement