开发者

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

开发者 https://www.devze.com 2023-03-08 08:36 出处:网络
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.

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

精彩评论

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

关注公众号