Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>if ("ontouchstart" in window || "ontouch" in window) { // bind the relevant functions to the 'touch'-based events for iOS } else { // use the classic mouse-events, 'mouseover,' 'click' and so on. } </code></pre> <p>I've tested this with the following simple demo, albeit without event-binding (as yet) in the full-screen <a href="http://jsfiddle.net/davidThomas/YJ4JN/1/embedded/result/" rel="nofollow noreferrer">JS Fiddle demo</a> (I've also made a TinyUrl to redirect to that demo, for ease of entry in the iOS devices: <a href="http://tinyurl.com/drtjstest2/" rel="nofollow noreferrer">tinyurl.com/drtjstest2/</a>).</p> <p>Revised demo, with event-allocated functions:</p> <pre><code>var body = document.getElementsByTagName('body')[0]; if ("ontouchstart" in window) { body.style.backgroundColor = 'red'; body.ontouchstart = function(){ this.style.backgroundColor = 'yellow'; }; body.ontouchend = function(){ this.style.backgroundColor = 'green'; }; } else { body.style.backgroundColor = 'green'; body.onmousedown = function(){ this.style.backgroundColor = 'yellow'; }; body.onmouseup = function(){ this.style.backgroundColor = 'red'; }; } </code></pre> <p><a href="http://jsfiddle.net/davidThomas/YJ4JN/2/" rel="nofollow noreferrer">JS Fiddle demo</a> (and the TinyUrled alternative: <a href="http://tinyurl.com/drtjstest2/" rel="nofollow noreferrer">tinyurl.com/drtjstest3/</a>).</p> <p>References:</p> <ul> <li>Questions and answers, here at Stackoverflow: <ul> <li><a href="https://stackoverflow.com/questions/2877393/detecting-support-for-a-given-javascript-event">Detecting support for a given JavaScript event?</a></li> <li><a href="https://stackoverflow.com/questions/4858172/ios-web-app-touch-gestures">iOS Web App touch gestures</a></li> </ul></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload