Here's a fiddle: http://jsfiddle.net/z9rnnLmn/3/
Because you want to do this on "drag" there is a slight timeout on mousedown before triggering the method on mouseup. Mouseup alone can get triggered on a common click which is the reason for the delay.
Good luck.
var DRAG = false;
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
$("body").on("mousedown", function () {
setTimeout(function () {
DRAG = true;
}, 250)
});
$("body").on("mouseup", function () {
if (DRAG) {
alert(getSelectionText());
DRAG = false;
}
});