Chrome首先进行双击

Chrome首先进行双击

本文介绍了Chrome首先进行双击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

当人们在我的页面上双击一个大的DIV时,我抓住双击并在大DIV内创建一个小的彩色DIV。我结束了我的双击处理程序,并带有

  e.preventDefault(); 
返回false;

让浏览器免受双击。



这在Firefox中正常运行。



但在Chrome中,第一次在大DIV中双击,在页面加载之后将大DIV变成蓝色,然后继续创建小型彩色框。



由于某些原因,Chrome在我做之前得到了第一次双击,并且认为我想选择大的DIV,所以它将它变成蓝色。 (蓝色是Chrome提供的所有内容的蓝色,双击Google搜索页面上的内容即可查看它。)



一旦我点击大号DIV取消选择它,蓝色消失并在大DIV中双击不再转到Chrome。



任何人都可以解释Chrome在我之前是如何获得第一次双击的,以及如何防止这种情况发生?

感谢您的帮助。

解决方案

您可以添加CSS以防止在支持的浏览器中双击选择:

  div#element_to_target {
-webkit-user-select:none;
-moz-user-select:none;
-khtml-user-select:none;
-ms-user-select:none;
}

或者在事件处理函数中执行
$ (''dblclick',function(e){

// do stuff
$($'$'$'$'$'$'$' b $ b if(window.getSelection){
window.getSelection()。removeAllRanges();
} else if(document.selection){
document.selection.empty();
}
});


When people double-click in a large DIV on my page, I catch the double-click and create a small colored DIV inside the large DIV. I end my double-click handler with

    e.preventDefault();
    return false;

to keep the browser from getting the double-click.

This works fine in Firefox.

But in Chrome the first double-click in the large DIV, after the page loads turns the large DIV blue, and then goes on to create the small colored box.

For some reason Chrome got the first double-click before I did and thought I wanted to select the large DIV, so it turned it blue. (The blue is the same blue that Chrome gives everything that it selects. Double-click something on the Google search page to see it.)

Once I click off the large DIV to deselect it, the blue goes away and double-clicks in the large DIV no longer go to Chrome.

Can anyone explain how Chrome is getting the first double-click before I am, and how I can prevent this?

Thanks for your help.my

解决方案

You could either add CSS to prevent selection on double-click in supported browsers:

div#element_to_target {
    -webkit-user-select : none;
    -moz-user-select    : none;
    -khtml-user-select  : none;
    -ms-user-select     : none;
}

or do it in the event handler

$('div').on('dblclick', function(e) {

    // do stuff

    if (window.getSelection) {
        window.getSelection().removeAllRanges();
    } else if (document.selection) {
        document.selection.empty();
    }
});

这篇关于Chrome首先进行双击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:55