Constantly confronted with the fact that some scripts do not work on the iPhone. In particular, I now encountered such a problem, the following script does not work on different models on the iPhone (the problem is definitely not in the browser, I checked it in safari, chrome, yandex browser):

$(document).on('click', '.modal-layer__closure', function () { $(this).closest('.modal-layer').removeClass('active'); return false; }); 

Can someone explain the reason and how to continue to avoid such problems?

  • Where is the mistake..? - And
  • By clicking, the modal window should close, and everything works fine on all devices except the iphone, but I don’t know how to find out the cause of the failure - Anatoly Shevelev
  • Maybe you just turned off javascript. And so, for debugging. Read how to debug sites through the phone. - And
  • javascript is not turned off, most of the scripts are working fine, except for a few listeners like the ones listed above - Anatoly Shevelev
  • one
    This code does not depend on the phone, but on the version of the jquery library. Download the debugger and see what the error is, and no one will guess. - And

1 answer 1

I found the cause of the error:

on iOS devices, the 'click' event only works for links and (possibly) for elements with the tabindex attribute!

I hung the listener on the div element

The best option: use for the mobile version of the event 'touchstart', 'touchend' , etc.

  • one
    even on a div, you can hang a jquery click event, just add the css property cursor: pointer - Anser
  • Perhaps, but this is not at all obvious, therefore it is better to use 'touchend' - Anatoly Shevelev