已经讨论了如何禁用文本被选中: How to disable text selection highlighting using CSS?
但是,我还没有找到一种解决方案来阻止用户在从预期目标外部拖动时选择文本。我正在寻找适用于 IE 7/8 的解决方案。
有什么想法吗?
最佳答案
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 */
}
关于html - 在 IE7/8 中从外部目标拖动时防止文本选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9692036/