Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove selection using javascript

I'm working on a image viewer that has a draggable scrollbar. When the user drags the scrollbar, some of the text on the webpage becomes selected. I've tried

window.getSelection().removeAllRanges();

but that doesn't seem to work in IE7/8. Also tried the

document.getSelection().removeAllRanges();

which seems to work just as "well" with IE7/8.

Are there any other ways of doing this? Don't know of any jQuery solutions, but if there are, let me know (:

EDIT: This is the context of the onmouse-event

$("#slideBar").mousedown(function(f) {
    mouseDown = true;
    some more code...
}

$(document).mouseup(function() {
    if (mouseDown) {
       window.getSelection().removeAllRanges();
       more code...
    }
}
like image 784
peirix Avatar asked Dec 30 '22 01:12

peirix


1 Answers

Try returning false on the functions you use, especially for the "mousedown" event. Also returning false on document.onselectstart and document.ondragstart would help.

like image 75
BYK Avatar answered Jan 08 '23 02:01

BYK