javascript - Is it possible to set Range object as "backwards selection"? - Stack Overflow

I create a Range object and then add this Range to selectionwindow.getSelection ().addRange(myRange);Ho

I create a Range object and then add this Range to selection

window.getSelection ().addRange(myRange);

How to set the selection direction? I mean direction which can be checked using the anchorNode, anchorOffset, focusNode and focusOffset properties of selections.

I create a Range object and then add this Range to selection

window.getSelection ().addRange(myRange);

How to set the selection direction? I mean direction which can be checked using the anchorNode, anchorOffset, focusNode and focusOffset properties of selections.

Share Improve this question asked Oct 7, 2011 at 23:13 solaruasolarua 933 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You can do this on browsers that support the extend() (MDN) method of Selection objects. Mozilla, WebKit and Opera support it; IE does not up to and including version 11. extend() has been added to the HTML Editing APIs spec so it may yet appear in IE.

Here's an example function:

function selectRangeBackwards(range) {
    if (typeof window.getSelection != "undefined") {
        var sel = window.getSelection();
        if (typeof sel.extend != "undefined") {
            var endRange = range.cloneRange();
            endRange.collapse(false);
            sel.removeAllRanges();
            sel.addRange(endRange);
            sel.extend(range.startContainer, range.startOffset);
        }
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744983026a4604452.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信