2

I must be doing it wrong because even though it works on IE9+, Edge, ff, chrome, and android it doesn't work on IOS. This code, on IOS, will just keep on a runnin'. Is there a way to fix this?

function handleeeee() {
    alert("HANDL-O");
    document.body.removeEventListener("touchstart", handleeeee);
}
document.body.addEventListener("touchstart", handleeeee, { once: true }); 
user875234
  • 2,399
  • 7
  • 31
  • 49
  • There are workarounds of course, a straightforward one is to use a variable. –  Feb 27 '18 at 13:50
  • var handleeeeeeeeee = function() {}? I get the same thing. – user875234 Feb 27 '18 at 13:52
  • No, you use a separate variable to track whether the handler should run. Example: https://jsfiddle.net/3cudjnp9/ –  Feb 27 '18 at 14:01
  • Yeah but I shouldn't have to hack it like that. But since doing it the right way doesn't work all I am left with is hacks. I am very confused why removeEventListener doesn't work. I can call removeEventListener immediately after addEventListener and it will still call handleeeee. – user875234 Feb 27 '18 at 14:11
  • 1
    I assume you're talking about the iOS version of Safari? According to the [docs](https://developer.apple.com/documentation/safariextensions/safarieventtarget/1635368-removeeventlistener) the parameters need to match exactly. They don't in the code in your question. Maybe that's the reason? –  Feb 27 '18 at 14:14
  • Yep, that was it. The third parameter. Thanks. – user875234 Feb 27 '18 at 14:30

0 Answers0