How to prevent text select outside HTML5 canvas on double-click?

后端 未结 3 1294
一向
一向 2021-02-14 19:16

(In every browser I\'ve tried) double-clicking on an HTML5 canvas selects any text immediately following the canvas element. I\'d prefer to keep the clicks confined to the canv

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-14 19:49

    I have run into a very similar circumstance where I was enabling the ability to drag and drop elements around the page using javascript.

    To solve this problem, you have the ability to capture the text selection event and on capture of the event if you return false, the selection will never take place.

    For a good example of this being put to use, please reference: http://www.dynamicdrive.com/dynamicindex9/noselect.htm

    Alternately if you are familiar with the jQuery framework, a perfectly simplistic and effective plugin is available at: http://chris-barr.com/entry/disable_text_selection_with_jquery/

    Bets luck to you!

提交回复
热议问题