在IE7 / 8中从外部目标拖动时阻止文本选择

时间:2012-03-13 20:57:47

标签: html css internet-explorer internet-explorer-8 internet-explorer-7

已经讨论了如何禁用被选中的文本: How to disable text selection highlighting using CSS?

但是,我还没有找到阻止用户在从预定目标外部拖动时选择文本的解决方案。我正在寻找适用于IE 7/8的解决方案。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

已经讨论过IE8- onselectstart eventunselectable 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 */
}
相关问题