开发者

jQuery trigger click mobile Safari (iPad)

开发者 https://www.devze.com 2023-01-12 10:24 出处:网络
I have stumbled upon a bug in Safari on iPad. $开发者_JAVA百科(\'#next_proj a\').trigger(\'click\');

I have stumbled upon a bug in Safari on iPad.

$开发者_JAVA百科('#next_proj a').trigger('click');

.. does not seems to click on the actual link.

Any clues?


I got this to work by doing this...

var el = $('#next_proj a').get(0);
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);

Hope it helps...


It may not be a bug. My guess is that they did not want to allow javascript emulated user clicks.


Have you tried triggering a touch event instead of a click event? Not sure how you would implement in jquery - but it isn't too complicated in plain js

function simulateEvent() {
  var e = document.createEvent('HTMLEvents');
  e.initEvent('touchstart',true, true);
  document.dispatchEvent(e);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消