Reputation: 13848
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?
Upvotes: 4
Views: 2308
Reputation: 99680
JQuery UI supports touch
for devices. . You could bind click and touch listeners on the same set of events.
$(window).bind("click touchstart", function(){...});
Upvotes: 5
Reputation: 47687
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.
Upvotes: 4