已经讨论了如何禁用被选中的文本: How to disable text selection highlighting using CSS?
但是,我还没有找到阻止用户在从预定目标外部拖动时选择文本的解决方案。我正在寻找适用于IE 7/8的解决方案。
有什么想法吗?
答案 0 :(得分:1)
已经讨论过IE8- onselectstart event和unselectable attribute解决方案。
CSS solution也已发布。这是要点:
<!-- save this file as unselectable.htc and remember where you put it -->
<public:component lightweight="true">
<public:attach event="ondocumentready" onevent="unselectable()" />
<script type="text/javascript">
function unselectable(){
element.onselectstart = function(){ return false; };
element.setAttribute('unselectable', 'on', 0);
}
</script>
</public:component>
/* add this rule to the existing CSS file */
.unselectable {
user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
behavior: url(unselectable.htc); /* change this path as needed */
}