user495688
user495688

Reputation: 973

get range and coordinate of selected text

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).

Upvotes: 4

Views: 3803

Answers (4)

Ata Iravani
Ata Iravani

Reputation: 2206

You can find the exact answer here

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

Upvotes: 0

Tim Down
Tim Down

Reputation: 324567

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.commonAncestorContainer;
        if (el.nodeType != 1) {
            el = el.parentNode;
        }
    }
    return el;
}

Upvotes: 3

Chinmayee G
Chinmayee G

Reputation: 8117

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

Upvotes: 0

Simon
Simon

Reputation: 3539

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

Upvotes: 0

Related Questions