如何防止在 Google Chrome 中选择文本?

2024-04-26

没有 oEvent.preventDefault();在GC工作?我需要防止在触发 onmove 事件时选择文本。

EDIT:事实证明这很容易......

function disableSelection() {
   document.onselectstart = function() {return false;} // ie
   document.onmousedown = function() {return false;} // others
}
function enableSelection() {
   document.onselectstart = null; // ie
   document.onmousedown = null; // others
}

之后,移动事件上不会触发任何文本选择(即,在选择事件上 - 即 - 确实是!)


-webkit-user-select: noneCSS 样式控制是否允许用户选择
元素的文本。

为了完整起见,这涵盖了所有支持的浏览器(IE 不被视为网络浏览器):

.no-select
{
   user-select: none;
   -o-user-select:none;
   -moz-user-select: none;
   -khtml-user-select: none;
   -webkit-user-select: none;
}

要通过 Javascript 完成此操作,只需创建一个类并添加节点的属性。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何防止在 Google Chrome 中选择文本? 的相关文章