How can I disable Text Selection temporarily using JavaScript?

后端 未结 2 1423
南旧
南旧 2020-12-10 12:40

this is a bit of a specific question so I\'ll get right to the point.

I\'m working on a short and simple drag and drop routine for part of a web application, and alt

相关标签:
2条回答
  • 2020-12-10 12:50

    as far I know, dragged element must be positioned over other elements under mouse pointer. If it will moving with the mouse pointer, it prevent any selections on the page.

    0 讨论(0)
  • 2020-12-10 13:06

    In W3C browsers, you can call the preventDefault method on the event object. The IE equivalent is to set the returnValue to false.

    function stopDefault(e) {
        if (e && e.preventDefault) {
            e.preventDefault();
        }
        else {
            window.event.returnValue = false;
        }
        return false;
    }
    

    EDIT: Just re-read the question and you might also want to prevent the default action in the part of your code that handles the actual dragging, and not just at the initial mousedown or click.

    0 讨论(0)
提交回复
热议问题