Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Disabling Menubar of IE using JavaScript


Message #1 by "Sunil A" <sunil_k_a@h...> on Fri, 28 Sep 2001 21:52:19
Hi Sunil

There is a way to trap the keys on IE5.0 and above. It involves using the 
event object, which stores all the current information about the mouse and 
key strokes, as well as other stuff.

To check if CTRL+N is being pressed, you can use this quick bit of code

--------------------
<script>
// function called every time a key is pressed down
function checkKP()
{
  if(event.ctrlKey)
    if((event.keyCode == 78) || (event.keyCode == 104))
      event.returnValue = false;
}
</script>
<body onkeydown="checkKP()">
</body>
--------------------
When any key is pressed, the checkKP() function is called. If the CTRL key 
is being held down, it then checks the ASCII code for the other key that 
has just been pressed.  If this is 78 (N) or 104 (n), it cancels the event 
being run, by calling event.returnValue = false;

You can use the same sort of thing when a window unloads by writing
<body onbeforeunload="event.returnValue = false;">
This stops the window from closing.

Good Luck
  Phil

  Return to Index