Heads up! This post was written 14 years ago. Some information might be outdated or may have changed since then.
Една малка функция която връща селектирания текст от потребителя.
function getSelectedText() {
    var txt = '';
    if (window.getSelection) {
        txt = window.getSelection();
    } else if (document.getSelection) {
        txt = document.getSelection();
    } else if (document.selection) {
        txt = document.selection.createRange().text;
    } else
        return;
    return txt.toString();
}

Тествано на: IE9,Firefox,Chrome

Back to all posts