Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android browser touch event location

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?

like image 841
Vince Avatar asked Feb 23 '23 05:02

Vince


1 Answers

This 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);
like image 90
Kevin Ennis Avatar answered Feb 26 '23 10:02

Kevin Ennis