onclick not working on iPhone
Hi,
an onclick I'm using doesn't seem to work on iPhones, although it's fine elsewhere.
My code is
Code:
document.onclick = function(){newTarg(speedS)};
Any thoughts of a way round this? I thought maybe onchange would do it but not sure how to implement it?
Cheers,
Derek
Click events don't work on iOS, you'd have to use the touchstart, touchmove and touchend events to work out if the users tapped the screen.
Code:
<script>
var tap = true;
document.addEventListener('touchstart',function(e) {
tap = true;
});
document.addEventListener('touchmove',function(e) {
tap = false;
});
document.addEventListener('touchend',function(e) {
if(tap) {
//users tapped the screen
}
});
</script>
Something along the lines of that.
Thanks, that seems to get me some of the way there. I'm guessing to register a 'double click' I'll need to do it manually - set a timer on the first touch, and if a second touch happens within a set time, it's a double click?
And how would I get the coordinates of the touch? I'm using
Code:
evt = window.event;
targX = evt.clientX;
targY = evt.clientY;
for the mouse click.
Is there something similar, eg ?
Cheers for the help - bit of a JS newbie...
You can see where the user tapped the page using the changedTouches object
Code:
<script>
var tap = true;
document.addEventListener('touchstart',function(e) {
tap = true;
});
document.addEventListener('touchmove',function(e) {
tap = false;
});
document.addEventListener('touchend',function(e) {
if(tap) {
var touch = e.changedTouches[0];
var pageX = touch.pageX;
var pageY = touch.pageY;
}
});
</script>
Superb, thanks very much!
I recently developed a simple game for a web site intended for desktop browsers only using click events for interaction..
Feedback received was that both iOS and Android phones worked without any problems as the OS converted the click events to TOUCH events.
I did not use the onClick style to register an event but the click event registered with the addEventListener.
The conversion was unexpected so kudos to the mobile developers in both camps
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks