Window.click not starting in Safari for iPad

This code works fine in desktop browsers:

$(window).click(function() {...}); 

But in Safari on the iPad, it just doesn't work. Isn't it supported? What is the correct notification method when someone touches somewhere in a browser window?

+4
source share
2 answers

JQuery UI supports touch for devices. You can link clicks and touch listeners in the same set of events.

 $(window).bind("click touchstart", function(){...}); 
+5
source

Try it like this:

 var clickOrTap = ( typeof document.body.ontouchend === "undefined" ) ? 'click' : 'touchend'; $( "body" ).on( clickOrTap, function() { ... } ); 

It checks if the device has a touchend event, and if this does not mean that you are on the desktop, so that the listener will wait for a click . If it is defined, then you are on the touch device and you can listen to touch events.

+4
source

Source: https://habr.com/ru/post/1445544/


All Articles