【问题标题】:How can I prevent the selection of text in IE?如何防止在 IE 中选择文本?
【发布时间】:2019-12-13 16:52:36
【问题描述】:

我有以下 CSS:

    * {
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
        user-select: none;
    }

这在除 IE 之外的所有浏览器中都有效,这是为什么呢?文本的选择看起来真的很难看,因为我的菜单是由文本和 CSS 创建的……有什么想法吗?

【问题讨论】:

标签: html css internet-explorer


【解决方案1】:

您可以使用 Javascript 并执行以下操作:

document.onselectstart = function() { return false; }
document.onmousedown = function() { return false; }

第一个适用于 IE,第二个适用于基于 Mozilla 的浏览器。

【讨论】:

  • 如果您想阻止在单个元素中进行选择怎么办?我相信 document.getElementById("foo").onselectstart = function(){return false} 在这里无济于事。
  • 这是在 Internet Explorer 7 中禁用选择文本的唯一方法,我在 delphi 的 TWebBrowser 中对其进行了测试,它可以工作!
【解决方案2】:

对于 IE11 我使用了

-ms-user-select: none;

它成功了

【讨论】:

    猜你喜欢
    • 2015-09-27
    • 2011-01-19
    • 1970-01-01
    • 2017-07-11
    • 2012-04-28
    • 1970-01-01
    • 2012-11-22
    • 1970-01-01
    • 2012-07-13
    相关资源
    最近更新 更多