检测浏览器/设备是否支持双击事件 [英] Detect if browser/device supports double click events

查看:126
本文介绍了检测浏览器/设备是否支持双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多行的表。
通过在行上单击一次可以选择每行。
双击该行会打开该行在同一窗口中显示的数据表。

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.

我试过检测dblclick事件是否在我的Android设备上可用,它是。

我想这是有意义的,因为浏览器确实如此支持它,但设备只是在双击时触发不同的事件。

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.

我能想出的另一件事是检查 touchstart 等事件可用,但这似乎与检查用户代理一样错误。

The only other thing I could come 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?

推荐答案

也许尝试使用超时来检查第一次点击后是否有另一次点击

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);
});

这篇关于检测浏览器/设备是否支持双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆