I'm building a tablet version of a website. I am using custom touchevents to detect swiping and moving a HTML element accordingly. With the HTML element is an A tag with an HREF. On an iPad, when I tap the link, it does not go to the URL.
What is the best method to trigger a link within a touchevent?
Figured it out. Hopefully, this question/answer will help someone else out...I had some difficulty finding a good answer out there.
Stole the util.click snippet from iScroll ( https://github.com/cubiq/iscroll/blob/master/src/utils.js ).
function click(e) {
var target = e.target,
ev;
if ( !(/(SELECT|INPUT|TEXTAREA)/i).test(target.tagName) ) {
ev = document.createEvent('MouseEvents');
ev.initMouseEvent('click', true, true, e.view, 1,
target.screenX, target.screenY, target.clientX, target.clientY,
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
0, null);
ev._constructed = true;
target.dispatchEvent(ev);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.