开发者

getting user selection, and not only the text but also the html tags

When a user selects text, I need to be able to get it "as is" with all html tags, is that possible? I have a function that gives me only the text.

function smth() {

    if (document.getSelection) {
        var str = document.getSelection();
 开发者_开发百科       if (window.RegExp) {
            var regstr = unescape("%20%20%20%20%20");
            var regexp = new RegExp(regstr, "g");
            str = str.replace(regexp, "");
        }
    } else if (document.selection && document.selection.createRange) {
        var div = document.createElement('div');
        div.appendChild(range.cloneContents());
        str = div.innerHTML;
        //var range = document.selection.createRange();
        //var str = range.text;
    }

    return str;

}

It gives me the selection text, but I need to know if the person clicked on 2 different links, because I need to get both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜