Seleziono del testo sulla pagina html (aperto in firefox) usando il mouse, e usando le funzioni javascript, creo/ottengo l'oggetto-intervallo corrispondente al testo selezionato.Come posso evidenziare il testo dell'oggetto DOM Range?
userSelection =window.getSelection();
var rangeObject = getRangeObject(userSelection);
ora voglio evidenziare tutto il testo che rientra nel rangeobject.I sto facendo in questo modo,
var span = document.createElement("span");
rangeObject.surroundContents(span);
span.style.backgroundColor = "yellow";
Bene, questo funziona bene, solo quando il rangeobject (punto iniziale e finale) si trova nella stessa TextNode, allora evidenzia la corrispondente text.Ex
<p>In this case,the text selected will be highlighted properly,
because the selected text lies under a single textnode</p>
Ma se il rangeobject riguarda più TextNode, properlay allora non funziona, si evidenzia che solo i testi trovarsi nella prima TextNode, Ex
<p><h3>In this case</h3>, only the text inside the header(h3)
will be highlighted, not any text outside the header</p>
Qualsiasi idea di come posso fare, tutti i testi che rientra rangeobject, evidenziato, indipendentemente dal fatto gamma risiede in un singolo nodo o più nodi? Grazie ....
Possibile duplicato: http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button –