javascript - Detect if browserdevice supports double click events - Stack Overflow

I have a table containing multiple rows. Each row is selectable by clicking once on the row.Double cl

I have a table containing multiple rows. Each row is selectable by clicking once on the row. Double clicking the row opens up the datasheet the row represents in the same window.

When using a mobile device, the double click (double tap?) doesn't trigger my double click event, and the mobile browser just zoom instead.

After giving it some thought, I reckon it makes more sense for mobile devices to open the datasheet with a single click/tap anyway.

Right now I'm detecting if it's a mobile device browser, when setting up the event listener for the table, with this code:

if( /Android|webOS|iPhone|iPad/i.test(navigator.userAgent) ) {
    // Single click event bind, open
} else {
    // Single click event bind, select
    // Double click event bind, open
}

Instead of relying on the user agent, I woud much rather do some feature detection, so any device unable to make a double click works.

I tried detecting if the dblclick event is available on my Android device, and it is.
I guess this makes sense, since the browser does support it, but the device just triggers a different event when double tapping.

The only other thing I could e up with is checking if the touchstart etc. events are available, but that seems about as wrong as checking the user agent.

Is there any good way to detect if the browser / client supports double clicks as expected?

I have a table containing multiple rows. Each row is selectable by clicking once on the row. Double clicking the row opens up the datasheet the row represents in the same window.

When using a mobile device, the double click (double tap?) doesn't trigger my double click event, and the mobile browser just zoom instead.

After giving it some thought, I reckon it makes more sense for mobile devices to open the datasheet with a single click/tap anyway.

Right now I'm detecting if it's a mobile device browser, when setting up the event listener for the table, with this code:

if( /Android|webOS|iPhone|iPad/i.test(navigator.userAgent) ) {
    // Single click event bind, open
} else {
    // Single click event bind, select
    // Double click event bind, open
}

Instead of relying on the user agent, I woud much rather do some feature detection, so any device unable to make a double click works.

I tried detecting if the dblclick event is available on my Android device, and it is.
I guess this makes sense, since the browser does support it, but the device just triggers a different event when double tapping.

The only other thing I could e up with is checking if the touchstart etc. events are available, but that seems about as wrong as checking the user agent.

Is there any good way to detect if the browser / client supports double clicks as expected?

Share Improve this question edited Jan 16, 2013 at 8:13 Wertisdk asked Jan 16, 2013 at 8:04 WertisdkWertisdk 1682 silver badges12 bronze badges 2
  • U use this event? $(elm).dblclick(); – Hodaya Shalom Commented Jan 16, 2013 at 8:10
  • @HodayaShalom Yes, that's the jQuery event I'm using. Adding jQuery to my tags, to clarify that jQuery is available in my case. – Wertisdk Commented Jan 16, 2013 at 8:12
Add a ment  | 

1 Answer 1

Reset to default 6

Maybe try to use a timeout to check if there is an another click after the first click

$(Elm).click(function(evnt){
  clicks++;
  if (clicks == 1) {
    setTimeout(function(){
      if(clicks == 1) 
        // Single click event bind, open
       else 
         // Double click event bind, open
    },2000);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745226063a4617465.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信