Friday, 3 May 2013

Handling img click event on mobile devices

The following is the snippet for handling click event on mobile devices:

<script>
    var touchflag = false;
          $("img").bind("touchstart", function(event)
              {
                 touchflag = false;
              }); 

          $("img").bind("touchmove", function(event)
             {
                touchflag = true;
             }); 

          $("img").bind("touchend", function(event)
            {
            if(touchflag) return;
           
            name = $(this).parent().attr("id");
            window.open("pageToOpen.html?q="+name,"_self");
          }); 

</script>

No comments:

Post a Comment