2009
Apr
15




Disable Text Selection

With CSS

Example
  1. <div unselectable="on"></div> /* For IE */
Example
  1. .text-selection {
  2. user-select: none;
  3. -moz-user-select: none; /* For Firefox */
  4. -khtml-user-select: none; /* For Safari */
  5. -o-user-select: none; /* For Opera */
  6. }

With JavaScript

Example
  1. var disableTextSelection = function(element) {
  2. element.unselectable = "on"; /* For IE */
  3. element.style.UserSelect = "none";
  4. element.style.MozUserSelect = "none"; /* For Firefox */
  5. element.style.KhtmlUserSelect = "none"; /* For Safari */
  6. element.style.OUserSelect = "none"; /* For Opera */
  7. };

回應 (Leave a comment)