1

I am currently working on Wes Bos' JavaScript 30 project, and in this drumkit project, I was hoping to add to his finished code by allowing user to click on the button rather than only through 'keydown' event.

After adding to the playSound function to detect

event.path[1].dataset.key || event.path[0].dataset.key

so that the click event would be able to grab the button's attribute, which contains the keyCode, and use that to detect which audio to play. Then I wrote this:

window.addEventListener('click', playSound);

and it worked great on desktop, it also worked great on my android smart phone, but for some reason the button doesn't work on an iphone.

So after looking through some similar results on stackoverflow, here's what I've tried:

window.addEventListener('touchstart', playSound)

and

 window.addEventListener('DOMContentLoaded', (event) => {
   window.addEventListener('touchstart', playSound)
 });

but neither of them seems to work on iphone. Is there something special about iphone that doesn't allow me to click a button using their touch screen? Android doesn't seems to have this issue at all.

1 Answers1

1

it turns out all i needed to do is use document.addEventListener instead of window.addEventListener for iOS