全局阻止Firefox中的文本选择

问题描述 投票:8回答:2

我目前正在使用:

*{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

转到http://jsfiddle.net/KyF5x/并单击列表下方,看到这突出显示文本...无法突出显示。重新加载页面,现在尝试ctrl + a,看到这也会突出显示文本。

Chrome,Safari或IE 10中不会出现上述情况。

免责声明:我使用的是Firefox 18

html css
2个回答
8
投票

作为临时答案,修复方法是将CSS应用于各个“不可选择的”元素。但是,我很乐意看到有人想出一个文档范围的修复程序。

li{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

见:http://jsfiddle.net/KyF5x/1/

具有文档范围的不可选文本的用例在Web应用程序领域中更为明显,而不是典型的网站。


2
投票

作为Jack答案的补充 - 即使在2018年,firefox也不支持用户选择,但支持moz-user-select。我选择了一个减少版本的接受答案中的小提琴:

/* stop the user selecting page structure with the mouse */
html, body, div, a, i, button, select, option, optgroup, hr, br {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  cursor: default;
}

这是一个Web应用程序,我们不使用任何其他元素,所有页面结构都是div,甚至标题等,我们不想在输入或textarea中禁止选择。

这是我们整个网络500k代码应用程序中唯一的地方,我们必须使用-moz- !!

© www.soinside.com 2019 - 2024. All rights reserved.