Answer the question
In order to leave comments, you need to log in
How to remove alt activity?
Hello everyone
I ran into such a problem: when I enter some text in input or div[contenteditable] I want my function to be called when alt is pressed, the
problem is that in Chrome (possibly in other browsers, not tested) when I click on alt focus is lost from the field (when pressed again, it returns back). Peculiar toggleFocus (joke for 300) The
question is how to make it so that when I press alt, only my function fires and nothing else?
Answer the question
In order to leave comments, you need to log in
On Windows, any window interprets pressing the alt key as an action that initiates the opening of the current window's menu. And, as a result, the focus of your input is lost.
To prevent this situation use preventDefault
var element = document.querySelector("#InputID");
element.onkeyup = function(e){
var key = e.keyCode || e.which;
if(key===18) {
e.preventDefault();
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question