在IE7 / 8中从外部目标拖动时防止文本选择 [英] Prevent text selection when dragging from outside target in IE7/8
本文介绍了在IE7 / 8中从外部目标拖动时防止文本选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
讨论了如何禁止文本被选中:
如何禁用使用CSS的文本选择突出显示?
It has been discussed how to disable text from being selected: How to disable text selection highlighting using CSS?
然而,我还没有找到一个解决方案阻止用户从外部拖动时选择文本预定的目标。我正在寻找一个适用于IE 7/8的解决方案。
However, I have yet to find a solution that blocks the user from selecting text when dragging from outside the intended target. I'm looking for a solution that works in IE 7/8.
有什么想法?
Any ideas?
推荐答案
IE8- onselectstart event 和无法选择的属性解决方案已经被讨论。
The IE8- onselectstart event and unselectable attribute solutions have already been discussed.
CSS解决方案也已经发布。以下是要点:
The CSS solution has been published as well. Here is the gist:
<!-- 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 */
}
这篇关于在IE7 / 8中从外部目标拖动时防止文本选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文