javascript - get range and coordinate of selected text - Stack Overflow

How to select the text of the page in FireFox?For example, there's a paragraph of text, user sele

How to select the text of the page in FireFox? For example, there's a paragraph of text, user select the text in those paragraph in a regular way.then, I want to know in which paragraph the text selected by user (in which position-xy coordinates, range position).

How to select the text of the page in FireFox? For example, there's a paragraph of text, user select the text in those paragraph in a regular way.then, I want to know in which paragraph the text selected by user (in which position-xy coordinates, range position).

Share Improve this question edited Mar 3, 2019 at 10:20 Cœur 38.8k25 gold badges206 silver badges279 bronze badges asked Nov 11, 2010 at 9:46 user495688user495688 9632 gold badges15 silver badges26 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

You've asked about selection coordinates twice before. I know I've given you a working answer, so why are you asking again?

Here's some code that will return you the innermost element containing the selection in Firefox (assuming a single selection; Firefox allows multiple selections). Hope it's helpful.

function getSelectionContainerElement() {
    var sel = window.getSelection(), el = null;
    if (sel.rangeCount) {
        var range = sel.getRangeAt(0);
        el = range.monAncestorContainer;
        if (el.nodeType != 1) {
            el = el.parentNode;
        }
    }
    return el;
}

refer the getSelection(), to get an object which contains information about the selected text and its position in the parent Element

Selection - MDC might help you to find answer of all your questions.

You can find the exact answer here

but this module is under construction, You can browse project and find this module.

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

相关推荐

  • javascript - get range and coordinate of selected text - Stack Overflow

    How to select the text of the page in FireFox?For example, there's a paragraph of text, user sele

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信