highlight the text of the DOM range element,

Posted by ganapati on Stack Overflow See other posts from Stack Overflow or by ganapati
Published on 2010-05-03T08:38:45Z Indexed on 2010/05/03 8:48 UTC
Read the original article Hit count: 342

Filed under:
|
|
|
|

I am able to highlight the text on the HTML page(rendered through gtkmozembed), which is selected, like below.

    var range, sel;
    if (window.getSelection) {
        sel = window.getSelection();
        if (sel.getRangeAt) {
          range = sel.getRangeAt(0);
        }
        document.designMode = "on";
        if (range) {
            sel.removeAllRanges();
            sel.addRange(range);
        }
        document.execCommand("HiliteColor", false, colour);
        document.designMode = "off";
   }  

Well,it works very fine.Now i am trying to store the information(startNode, startOffset,endNode, endOffset) about the highlighted text, and next time when i open the same page,highlight the same text. I am able to successfully store the info and retrieve them when the same page opens. And i am trying to highlight the text using following code.

    var range = document.createRange();
    range.setStart(startNode, startOffset);
    range.setEnd(endNode, endOffset);

    document.designMode = "on";
    range.execCommand("HiliteColor", false, colour);
    document.designMode = "off";

But it is not working as i am expecting. Can anyone help me to achieve the required? Thanks...

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom