views:

210

answers:

2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
    <script language="JavaScript" src="mootools-1.2.3-core-nc.js"></script>
    <script language="JavaScript" src="mootools-1.2.3.1-more-nc.js"></script>
 </HEAD>
 <BODY id='body'>
 </BODY>
  <Script> 
  function onkeydown(e){
      alert(e.key);
      e.keyCode=0;   
                    e.stop();
      return   false;   

    }
  Event.Keys.F3 = 114;
  window.addEvent('domready', function() {
        document.addEvent("keydown", this.onkeydown);
                    }) ;
       </script>
</HTML>

when open it in ie8,press F3,the search action comes.why can't stop it?

+1  A: 

Because that is the browser's default action and there is almost never a good excuse to override expected behavior.

See http://stackoverflow.com/questions/1592847/how-can-i-disable-alt-enter-in-ie/1592868#1592868 for a recent discussion on disabling ALT-Enter in IE.

Jonathan Fingland
+1  A: 

Internet Explorer, and most other browser for that matter, lock usage of the F keys from JavaScript. The rebinding of these keys is prohibited for obvious reasons; imagine the chaos if we allowed the rebinding of the F5 key!

The technical answer is that the keydown and keyup event is intercepted before it reaches the JS layer by the application. Just as you can return true or false in an event to prevent propagation, the application stops propagation of the keydown and keyup events to scripting interfaces outside of its trusted domain, eg. you can override the F3 key only inside browser Add On's and Toolbars, but not inside web pages.

In a nutshell: try rebinding another key, F keys are not easily cross-browser rebindable.

Nathan Kleyn