I'm using Firefox 65.0 for my web development. My project code contains password input. I developed this before more than a year ago using JS code that detects the key presses using onkeydown
and onkeyup
functions. It works fine for all browsers except the new Firefox version 65.0
My code is similar to this:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type=password id="button" autocomplete_="off"></input>
<script>
$("#button").keydown(function(event) {
console.log("key: " + event.key);
});
document.getElementById("button").onkeydown = function(event) {
console.log("key: " + event.key);
};
</script>
For both cases the event.key
value is not the pressed button, but it's just "Process"
as a string. Does someone have an idea why I get this result? How can I solve it and detect the real pressed key value?
My OS version: is ubuntu 18.04
Edit: add debug screen shot
In addition I can't find any attribute under event that can help me
you can find below a screen shot of a debug in the onkeydown handler for the case of 'a' key.
There are quite a few different event properties for key codes, and they all return something a little bit different. Try
event.which
, and if that doesn't work, here's a list of other event propertiesEdited to provide additional info
I did some testing, the cause appears to be that your trying to log keypresses on an input of type="password". I tested your code snippet in Firefox after removing the type="password" and both
event.which
andevent.key
work normally. I suppose its intentionally obfuscated by Firefox to avoid scripts logging password keystrokes. If you need the value of the password, useevent.target.value
in the event listener. Also I would recommend using the 'keyup' event rather than keydown, or you run into the problem of the listener repeatedly firing when you hold down a key.With the password attribute
Without the password attribute