Domanda

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

È stato utile?

Soluzione 2

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)
    }
});

Altri suggerimenti

This should work for you.

Fiddle: http://jsfiddle.net/2dqCD/

This checks to see if alt was pressed on an input node, in the fiddle, you can see it will still allow the alt key outside of the input box.

Hope this helps.

document.addEventListener("keyup",function(e){    
    if(e.keyIdentifier == "Alt" && e.target.nodeName == "INPUT"){ 
        e.preventDefault ? e.preventDefault() : (e.returnValue=false)
    }
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top