现在的位置: 首页 > 综合 > 正文

Javascript selection的兼容性写法

2014年09月05日 ⁄ 综合 ⁄ 共 344字 ⁄ 字号 评论关闭
function getSelectedText() {    //this function code is borrowed from: http://www.codetoad.com/javascript_get_selected_text.asp

    var txt = "";
    if (window.getSelection) {
        txt = window.getSelection();
    } else if (window.document.getSelection) {
        txt = window.document.getSelection();
    } else if (window.document.selection) {
        txt = window.document.selection.createRange().text;
    }
    return txt;
}

抱歉!评论已关闭.