Je sélectionne du texte sur la page html (ouverte dans firefox) en utilisant la souris, et en utilisant les fonctions javascript, je crée/récupère l'objet rangeobject correspondant au texte sélectionné.Comment puis-je mettre en évidence le texte de l'objet DOM Range?
userSelection =window.getSelection();
var rangeObject = getRangeObject(userSelection);
Maintenant, je veux souligner tout le texte qui vient sous les rangeobject.I je fais comme ça,
var span = document.createElement("span");
rangeObject.surroundContents(span);
span.style.backgroundColor = "yellow";
Eh bien, cela fonctionne très bien, que lorsque le rangeobject (startpoint et point final) se trouve dans le même textnode, il met en évidence le correspondant text.Ex
<p>In this case,the text selected will be highlighted properly,
because the selected text lies under a single textnode</p>
Mais si le rangeobject couvre plus d'un textnode, il ne fonctionne pas properlay, il met en évidence que les textes se situer dans la première 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>
Toute idée de comment puis-je faire, tous les textes qui vient sous rangeobject, a souligné, indépendamment du fait que plage se trouve dans un seul nœud ou plusieurs nœuds? Merci ....
Copie possible: http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button –