Hello,
I wrote an addon pianomoz, https://addons.mozilla.org/en-US/firefox/addon/pianomoz/ so that artists can create their own musical instrument.
The music notes work very well on the keyboard, but there are often misfires using mouse click.
Does anyone know why?
I use for keybord :
window.addEventListener(“keydown”, function (event) {
if (event.defaultPrevented) {
return; // Should do nothing if the key event was already consumed.
}
and I use for mouse :
document.addEventListener(‘DOMContentLoaded’, function() {
var b1v = document.getElementById(‘b1v’);
b1v.onclick = function() {
toucheblanche1Press();
};
To start with:
Assigning to the ‘onload’ property of DOM nodes which you do not own is unacceptable.
To prevent vulnerabilities, event handlers (like ‘onclick’ and ‘onhover’) should always be defined using addEventListener.
Thank you very much for the reply.
I had written in the first versions “addEventListener”, but all the first click did not work, and the default often appeared after the first clik.
Can you tell me what form of writing to use with addEventListener, for all click to work?
it was :
function load() {
var cel1 = document.getElementById(“b1v”);
cel1.addEventListener(“click”, toucheblanche1Press, false);
…
Yes, it is solved, thank you very much.
In detail, I had a major error in the css code. I had set a too large displacement value in ‘: active.’ This error moved the object before the sound was played, so the click did not sound.
The fact of correcting the code js, allowed me to discover the error in the code css.
cordially