ios - Ignore multiple button taps after first one on iPhone webapp using jQuery Mobile? -


assume button in html5 webapp built jquery mobile.

if taps button a, call foo(). foo() should called once if user double taps button a.

we tried using event.preventdefault(), didn't stop second tap invoking foo(). event.stopimmediatepropagation() might work, stops other methods further stack , may not lead clean code maintenance.

other suggestions? maintaining tracking variable seems awfully ugly solution , undesirable.

you can set flag , check if it's ok run foo() function or unbind event time don't want user able use , re-bind event handler after delay (just couple options).

here's do. use timeout exclude subsequent events:

$(document).delegate('#my-page-id', 'pageinit', function () {      //setup flag determine if it's ok run event handler     var okflag = true;      //bind event handler element in question `click` event     $('#my-button-id').bind('click', function () {          //check see if flag set `true`, nothing if it's not         if (okflag) {              //set flag `false` event handler disabled until timeout resolves             okflag = false;              //set timeout set flag `true` enables event handler once again             //you can change delay timeout whatever may need, note units in milliseconds             settimeout(function () {                 okflag = true;              }, 300);              //and now, finally, run original event handler             foo();         }     }); }); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -