سؤال

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

هل كانت مفيدة؟

المحلول 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)
    }
});

نصائح أخرى

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)
    }
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top