On Safari, you can get the location of where the user touched the screen from event.pageX and event.pageY. However, on my Android browser, event.pageX and event.pageY are always 0. Is there any way to get the location of a touch event in the browser on Android?
On Safari, you can get the location of where the user touched the screen from event.pageX and event.pageY. However, on my Android browser, event.pageX and event.pageY are always 0. Is there any way to get the location of a touch event in the browser on Android?
Share Improve this question asked Dec 3, 2011 at 23:07 VinceVince 5899 silver badges16 bronze badges 1-
Could you elaborate a bit on what you're trying to acplish? Are you also interested in native options? E.g. like with any view, you can hook up a OnTouchListener to WebView and request the touch coordinates. Obviously, this will not work when zoomed in though. If you're after specific page elements,
getHitTestResult()
might also be worth looking at. – MH. Commented Dec 4, 2011 at 2:45
1 Answer
Reset to default 8This is from memory, since I don't own an Android device anymore, but I think it's right. At the very least, it should get you started in the right direction. Good luck.
var elem = document.getElementById('elem');
elem.addEventListener('touchend', function(e){
var pageX = e.changedTouches[0].pageX,
pageY = e.changedTouches[0].pageY;
}, false);