I'm close to developing a solution, kindly provided by ghostCoder, alluding to the idea of โโdetecting a touch event rather than a click event. This code below is what I have now, however something else is not quite right. It works on my homepage (a very simple page), however it breaks with the actual game page:
Here is my code: JAVASCRIPT:
var b=document.getElementById('STOP'),start=0; //Check for touchstart if('ontouchstart' in document.documentElement) { document.getElementById("notouchstart").style.display = "none"; } //Add a listener that fires at the beginning of each interaction [b].forEach(function(el){el.addEventListener('touchstart',interact);}); //Add the event handlers for each button b.addEventListener('touchstart',highlight); //Functions Store the time when the user initiated an action function interact(e) { start = new Date(); } //Highlight what the user selected and calculate how long it took the action to occur function highlight(e) { e.preventDefault(); e.currentTarget.className="active"; if(start) { alert("test") } start = null; }
BODY BUTTONS (first displays the start button, and then when the stop button is pressed, it stops, then it starts again, etc.)
<INPUT TYPE="button" style="background:url(images/Start_Btn.png); background-color:transparent; width:150px; height:186px; border:none; cursor:pointer;" id="START" onClick="startBTN();"> <INPUT TYPE="button" style="background:url(images/Stop_Btn.png); background-color:transparent; width:150px; height:186px; border:none; cursor:pointer;" id="STOP">
Thanks,
Landl partners
source share