faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

57 of 92 people (62%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How to disable the "Control N " to open new window and also similar commands in IE
Looking for window.event.keyCode for Control Copy and Control Print

Apr 7th, 2008 23:24
ha mo, Colin Fraser, Ananth Antony raj pichaikani, Anthony Hodge,


Here is an exercise I did ages ago, I have not had time to test it in
the new browsers but it did work in IE 5.+ and Netscape 6
 <HTML>
 <HEAD>
 <SCRIPT LANGUAGE="JavaScript1.2"><!--
 function netscapeKeyPress(e) {
     if (e.modifiers == 2) {
         // a - Select all
         // b - Edit bookmarks
         // c - Copy
         // d - Add bookmark
         if (e.which == 5 ) alert('Ctrl and e pressed'); 
         // f - Find in page
         // g - Find Again
         // h - Open History
         // i - Page Info
         if (e.which == 10) alert('Ctrl and j pressed');
         if (e.which == 11) alert('Ctrl and k pressed');
         if (e.which == 12) alert('Ctrl and l pressed');
         // m - New Message
         // n - New Navigator Window
         // o - Open Page
         // p - Print
         // q - Exit
         // r - Reload
         // s - Save As
         if (e.which == 20) alert('Ctrl and t pressed');
         // u - Page source
         // v - Paste
         // w - Close
         // x - Cut
         if (e.which == 25) alert('Ctrl and y pressed'); 
         // ?
     }
     else if (e.modifiers == 4) {
         if (e.which == 65) alert('Shift and A pressed');
         if (e.which == 66) alert('Shift and B pressed');
         if (e.which == 67) alert('Shift and C pressed');
         if (e.which == 68) alert('Shift and D pressed');
         if (e.which == 69) alert('Shift and E pressed');
         if (e.which == 70) alert('Shift and F pressed');
         if (e.which == 71) alert('Shift and G pressed');
         if (e.which == 72) alert('Shift and H pressed');
         if (e.which == 73) alert('Shift and I pressed');
         if (e.which == 74) alert('Shift and J pressed');
         if (e.which == 75) alert('Shift and K pressed');
         if (e.which == 76) alert('Shift and L pressed');
         if (e.which == 77) alert('Shift and M pressed');
         if (e.which == 78) alert('Shift and N pressed');
         if (e.which == 79) alert('Shift and O pressed');
         if (e.which == 80) alert('Shift and P pressed');
         if (e.which == 81) alert('Shift and Q pressed');
         if (e.which == 82) alert('Shift and R pressed');
         if (e.which == 83) alert('Shift and S pressed');
         if (e.which == 84) alert('Shift and T pressed');
         if (e.which == 85) alert('Shift and U pressed');
         if (e.which == 86) alert('Shift and V pressed');
         if (e.which == 87) alert('Shift and W pressed');
         if (e.which == 88) alert('Shift and X pressed');
         if (e.which == 89) alert('Shift and Y pressed');
         if (e.which == 90) alert('Shift and Z pressed');
     }
    else if (e.modifiers == 0) {
         Key = e.which;
         alert("Key pressed! ASCII-value: " + e.which);
 }
 }
 function microsoftKeyPress() {
     if (window.event.ctrlKey) {
         // a - Select All
         // b -Organise Favourites
         // c - Copy
         // d -Add to Favourites
         if (window.event.keyCode == 5 ) alert('Ctrl and e pressed');
         // f -Find (on this page)
         if (window.event.keyCode == 7 ) alert('Ctrl and g pressed');
         if (window.event.keyCode == 8 ) alert('Ctrl and h pressed');
         if (window.event.keyCode == 9 ) alert('Ctrl and i pressed');
         if (window.event.keyCode == 10) alert('Ctrl and j pressed');
         if (window.event.keyCode == 11) alert('Ctrl and k pressed');
         // l - Open
         if (window.event.keyCode == 13) alert('Ctrl and m pressed');
         // n - New Window
         // o - Open
         // p - Print
         if (window.event.keyCode == 17) alert('Ctrl and q pressed'); 
         // r - Reload
         // s - Save
         if (window.event.keyCode == 20) alert('Ctrl and t pressed');
         if (window.event.keyCode == 21) alert('Ctrl and u pressed');
         // v - Paste
         // w - Close
         // x -Cut
         if (window.event.keyCode == 25) alert('Ctrl and y pressed');
         if (window.event.keyCode == 26) alert('Ctrl and z pressed');
     }
     else if (window.event.shiftKey) {
         if (window.event.keyCode == 65) alert('Shift and A pressed');
         if (window.event.keyCode == 66) alert('Shift and B pressed');
         if (window.event.keyCode == 67) alert('Shift and C pressed');
         if (window.event.keyCode == 68) alert('Shift and D pressed');
         if (window.event.keyCode == 69) alert('Shift and E pressed');
         if (window.event.keyCode == 70) alert('Shift and F pressed');
         if (window.event.keyCode == 71) alert('Shift and G pressed');
         if (window.event.keyCode == 72) alert('Shift and H pressed');
         if (window.event.keyCode == 73) alert('Shift and I pressed');
         if (window.event.keyCode == 74) alert('Shift and J pressed');
         if (window.event.keyCode == 75) alert('Shift and K pressed');
         if (window.event.keyCode == 76) alert('Shift and L pressed');
         if (window.event.keyCode == 77) alert('Shift and M pressed');
         if (window.event.keyCode == 78) alert('Shift and N pressed');
         if (window.event.keyCode == 79) alert('Shift and O pressed');
         if (window.event.keyCode == 80) alert('Shift and P pressed');
         if (window.event.keyCode == 81) alert('Shift and Q pressed');
         if (window.event.keyCode == 82) alert('Shift and R pressed');
         if (window.event.keyCode == 83) alert('Shift and S pressed');
         if (window.event.keyCode == 84) alert('Shift and T pressed');
         if (window.event.keyCode == 85) alert('Shift and U pressed');
         if (window.event.keyCode == 86) alert('Shift and V pressed');
         if (window.event.keyCode == 87) alert('Shift and W pressed');
         if (window.event.keyCode == 88) alert('Shift and X pressed');
         if (window.event.keyCode == 89) alert('Shift and Y pressed');
         if (window.event.keyCode == 90) alert('Shift and Z pressed');
     }
     else if (window.event.keyCode== 24) alert('Up arrow pressed'); 
     else if (window.event.keyCode== 25) alert('Down arrow pressed');
     else if (window.event.keyCode== 26) alert('Right arrow pressed');
     else if (window.event.keyCode== 27) alert('Left arrow pressed');
     else if (window.event.keyCode== 49) alert('Number 1 pressed');
     else if (window.event.keyCode== 50) alert('Number 2 pressed');
     else if (window.event.keyCode== 51) alert('Number 3 pressed');
     else if (window.event.keyCode== 52) alert('Number 4 pressed');
     else if (window.event.keyCode== 53) alert('Number 5 pressed');
     else if (window.event.keyCode== 54) alert('Number 6 pressed');
     else if (window.event.keyCode== 55) alert('Number 7 pressed');
     else if (window.event.keyCode== 56) alert('Number 8 pressed');
     else if (window.event.keyCode== 57) alert('Number 9 pressed');
     else if (window.event.keyCode== 48) alert('Number 0 pressed');
     else if (window.event.keyCode== 59) alert('Number ; pressed');
     else if (window.event.keyCode== 13) alert('Enter pressed');
     else if (window.event.keyCode== 44) alert('comma pressed');
     else if (window.event.keyCode== 46) alert('full stop pressed');
 }
 if (navigator.appName == 'Netscape') {
     window.captureEvents(Event.KEYPRESS);
     window.onKeyPress = netscapeKeyPress;
 }
 //--></SCRIPT>
 </HEAD>
 <BODY onKeyPress="microsoftKeyPress()";>
<h2>Key Pressing</h2>
Use some shift and control keys. 
 </BODY>
 </HTML>
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com