admin管理员组文章数量:1415664
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
1 Answer
Reset to default 6Maybe 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);
});
本文标签: javascriptDetect if browserdevice supports double click eventsStack Overflow
版权声明:本文标题:javascript - Detect if browserdevice supports double click events - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745226063a2648611.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论