Getting coordinates of touchstart, touchend and click isn't working
Hi,
I'm trying to solve this problem for a long time now and I just can't get it to work properly.
I have the following code:
var win = Titanium.UI.createWindow();
var webview = Titanium.UI.createWebView({url: 'index.html'});
win.add(webview);
win.open({fullscreen:true, navBarHidden:true});
and in the HTML File I add the event listener (in a script block after the onload event of the body):
canvas.addEventListener('touchstart', function(e)
{
alert(e.x + " " + e.y);
});
(When I try it in the browser with 'onclick' it is working so there isn't any problem with the HTML or Javascript itself)
It alerts: "undefined undefined" and it just drives me crazy :-) Am I doing something wrong? Because according to the documentation this should work…
I really hope you could help me with this problem, I've searched the Q&A and the Docs but I just couldn't find the solution.
Thanks
1 Answer
-
Accepted Answer
Hi!
Since this eventListener is added in a WebView, you can't use e.x and e.y shorthands - you'll have to use the full HTML/JavaScript/DOM ones, namely:
canvas.addEventListener('touchstart', function(e) { alert(e.changedTouches[0].pageX + " " + e.changedTouches[0].pageY); });
Here is a great resource for touch events on the iPhone.
Cheers
/Jacob