【问题标题】:Prevent text selection when dragging from outside target in IE7/8在 IE7/8 中从外部目标拖动时防止文本选择
【发布时间】:2012-03-30 07:49:51
【问题描述】:

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

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

有什么想法吗?

【问题讨论】:

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


【解决方案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 */
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 2014-10-02
    • 2011-07-22
    • 2011-10-26
    • 1970-01-01
    相关资源
    最近更新 更多