This code works fine in desktop browsers:
$(window).click(function() {...});
But in Safari on the iPad, it simply doesn't fire. Is this not supported? What is the correct way to be notified when someone touches somewhere in the browser window?
This code works fine in desktop browsers:
$(window).click(function() {...});
But in Safari on the iPad, it simply doesn't fire. Is this not supported? What is the correct way to be notified when someone touches somewhere in the browser window?
Share Improve this question edited Nov 12, 2012 at 15:14 Oleg 9,3692 gold badges45 silver badges59 bronze badges asked Nov 12, 2012 at 15:11 Joshua FrankJoshua Frank 13.9k11 gold badges47 silver badges113 bronze badges 02 Answers
Reset to default 5JQuery UI supports touch
for devices. . You could bind click and touch listeners on the same set of events.
$(window).bind("click touchstart", function(){...});
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 it doesn't it means you're on desktop, so the listener will wait for click
. If it defined then you're on a touch device and you can listen for touch events.