Is there a way to track the selection range in an iframe designMode?

I experimented with this for a while, but didn’t get anything wrong - is there a way to track the mouse and selection in iframe designMode, preferably in a mode compatible with several browsers?

+3
source share
2 answers

Here is a small piece of code that I found here , hope this helps:

function setRange(rte) {
    //function to store range of current selection
    var oRTE;
    if (document.all) {
        oRTE = frames[rte];
        var selection = oRTE.document.selection;
        if (selection != null) rng = selection.createRange();
    } else {
        oRTE = document.getElementById(rte).contentWindow;
        var selection = oRTE.getSelection();
        rng = selection.getRangeAt(selection.rangeCount - 1).cloneRange();
    }
    return rng;
}

It looks like you can use the attribute selectionfor the document object and then use the method createRange(). if-elseprobably supports cross browser.

+2
source

Range Quirksmode. .

0

Source: https://habr.com/ru/post/1703508/


All Articles