if (window.getSelection) {
var text = window.getSelection();
}else if (document.getSelection) {
var text = document.getSelection();
}else if (document.selection) {
var text = document.selection.createRange().text;
}
var string = text.toString();
alert(string);