I'm creating a webpage were I want people to be able to press a button on their keyboard to play a sound and I have gotten this part to work by googling around a bit. Now however I want an on/off switch on the page that can turn the sound from the keyboard presses off so that people who don't want the keypresses to make a sound can have that option, is this possible?
Right now I'm using this JavaScript and HTML to play a sound whenever a button is pressed (A in this example):
JavaScript:
$(document).keydown(function(e){
if (e.keyCode == 65) {
document.getElementById('A').play();
return false;
}
});
HTML:
<audio id="A" src="A.ogg"></audio>