Search code examples
javascriptonclicktouch

Stop 300ms onclick delay on Android web browser


I have a page that plays an mp3 file when button pressed, using javascript like:

onclick="playAudio"

There is the obvious 300ms delay. I want to use this through html5 browsers only, using the nexus 7 only. So I dont want any backup code for IE6 etc. Every solution I've seen seems quite complicated and I can't get it to work.

Is there no simple javascript solution?


Solution

  • Check out the Fastclick project on github. If I understand your question, you just want to get rid of the 300ms delay on touch devices. This project is a polyfill to make touch uis much more snappy and responsive. Here is the url:

    https://github.com/ftlabs/fastclick

    Use Case:

    Just include the fastclick library like so:

    <script type='application/javascript' src='/path/to/fastclick.js'></script>
    

    And then just instantiate it by putting following in your main app js file:

    window.addEventListener('load', function() {
         new FastClick(document.body);
    }, false);
    

    Hope that helps!