【问题标题】:stopping firefox from selecting content on webpage [duplicate]阻止Firefox选择网页上的内容[重复]
【发布时间】:2011-02-16 22:41:34
【问题描述】:

可能重复:
What is the best way to prevent highlighting of text when clicking on its containing div in javascript?

当用户单击并拖动时,如何阻止 firefox 突出显示您的内容?

【问题讨论】:

  • 正如@TheifMaster 所说,我们知道您接受答案的程度,而且您做得越多,聪明人 给您答案的可能性就越大。 (smart != nice) 您可以通过单击否决票按钮下方的复选标记来执行此操作。
  • 请注意:任何有足够决心的人都会找到一种方法从您的页面上复制内容。

标签: javascript firefox highlighting


【解决方案1】:

这里已经回答了: What is the best way to prevent highlighting of text when clicking on its containing div in javascript?

基本上,对于 Firefox,您应该可以在 CSS 中做到这一点:

div.noSelect {
  -moz-user-select: none;//mozilla browsers
  -khtml-user-select: none;//webkit browsers
}

对于 IE,您显然可以“向 ondragstart 事件添加处理程序,并返回 false;”

【讨论】:

    【解决方案2】:

    如果您在页面上使用 jQuery UI,您可以简单地使用 $('body').disableSelection();

    如果没有,试试这个(这是disableSelection() 所做的):

    var elem = document.body;
    elem.onselectstart = function() { return false; };
    elem.MozUserSelect = 'none';
    elem.unselectable = 'on';
    

    【讨论】:

      【解决方案3】:

      您可以使用 IE 中的 unselectable expando 属性和其他浏览器中的 CSS 来执行此操作。有关详细信息,请参阅此答案:How to disable text selection highlighting using CSS?

      【讨论】:

        猜你喜欢
        • 2017-05-21
        • 2016-10-22
        • 1970-01-01
        • 1970-01-01
        • 2013-08-19
        • 1970-01-01
        • 1970-01-01
        • 2010-10-14
        • 2020-03-25
        相关资源
        最近更新 更多