0

After reading the responses to this question, I have implemented the same functionality where I check for event.preventDefault and either run event.preventDefault() or event.returnValue = false. This seems to have solved the problem for the user in the question but mine is still highlighting text. It is hitting the line event.returnValue = false in IE 7/8. It also works well in Firefox, Chrome, IE 9+.

A little more information: I am using a raphael canvas. I have the mousedown, mousemove, and mouseup events for the canvas all doing their own thing. I implemented the check for event.preventDefault in the mousedown callback function.

Community
  • 1
  • 1
AdamDev
  • 335
  • 4
  • 11
  • use css, something like http://stackoverflow.com/questions/826782/css-rule-to-disable-text-selection-highlighting – Chad Mar 12 '13 at 15:15
  • the css will not work because i still want to be able to drag/draw inside of the canvas element but if the user draws outside I do not want it to highlight any text – AdamDev Mar 12 '13 at 17:12

1 Answers1

0

If you're comfortable using jQuery, this will solve it cross-browser:

$(function (){
    $.fn.disableSelection = function() {
        return this
            .attr('unselectable', 'on')
            .css('user-select', 'none')
            .on('selectstart', false);
    };
})();
MattDiamant
  • 8,561
  • 4
  • 37
  • 46