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

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

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

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

有什么想法吗?

最佳答案

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 */
}

关于html - 在 IE7/8 中从外部目标拖动时防止文本选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9692036/

相关文章:

jquery - JavaScript、CSS、函数仅在 Internet Explorer 中不起作用

javascript - react 语义 Ui 按钮悬停

css - Internet Explorer 11 中的垂直对齐 + 垂直线性渐变错误

php - 多图上传如何制作呢?

html - 另一个站点的滚动效果

javascript - 使用什么方法在我的网站上显示背景?

css - 具有多个框架的单页 Web 应用程序具有重复的类名

html - CSS 3 列布局,高度灵活的侧边栏,SEO 代码顺序 : CONTENT-LEFT-RIGHT

html - 使面板可滚动的困难

css - IE 中的文本区域回退