faqts : Computers : Programming : Languages : JavaScript : Document

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

127 of 160 people (79%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How can I disable text selection (by mouse clicking/dragging)?
How can I disable text selection (by mouse clicking/dragging)?

Nov 5th, 2003 08:47
Klaus Bolwin, Martin Honnen,


With IE4+ the following works:
  if (document.all)
    document.onselectstart =
      function () { return false; };
With NN4 the following works
  if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown =
      function (evt) {
        return false;
      };
  }
but note that it cancels every mousedown action which will prevent 
other user action (link click, right click etc) as well.
For NN6
  document.onmousedown =
    function () { return false; };
disables text selection.
________________
For Mozilla & Co. you can use CSS to disable text selection:
selector {-moz-user-select:none;}