javascript - Detecting when user touches a link -
i'm trying detect when user has touched link within web page versus when have touched other part of page, not working - happens in following code alert "touched non link" pops wherever touch, regardless of if link.
what there problem code?
function addlisteners() { alert('adding listeners'); // attach listener touches on non-links document node document.addeventlistener("touchstart", touchesonnonlinkslisterner, false); // attach listener touches on links anchor nodes var links = document.getelementsbytagname("a"); (var index = 0; index < links.length; ++index) { links[index].addeventlistener("touchstart", touchesonnonlinkslisterner, false); } }; function touchesonnonlinkslisterner(event) // catches touches anywhere in document { alert("touched non link"); } function touchesonlinkslistener(event) // listens touches occur on links, prevents touch events bubbling trigger touchesonnonlinkslisterner { alert("touched link"); if (typeof event == "undefined") { event = window.event; } event.stoppropegation(); }
you have attached touchesonnonlinkslisterner links well. attach touchesonlinkslistener instead!
Comments
Post a Comment