最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - window.click does not fire on Safari for iPad - Stack Overflow

programmeradmin2浏览0评论

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 0
Add a ment  | 

2 Answers 2

Reset to default 5

JQuery 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.

发布评论

评论列表(0)

  1. 暂无评论