Search code examples
javascriptbrowserdom-eventsalt-key

Browser: hold "Alt" key focus on input text


When user is typing in a html input text, is it possible to keep the browser from showing its menu when the user press the Alt key deliberately or by mistake


Solution

  • here is @Runtis code modified just changed e.keyIdentifier == "Alt" to 18==e.keyCode
    http://jsfiddle.net/2dqCD/13/

    document.addEventListener("keyup",function(e){    
        if(18 == e.keyCode && e.target.nodeName == "INPUT"){ 
            e.preventDefault ? e.preventDefault() : (e.returnValue=false)
        }
    });