Required JAVASCRIPT or JAVA Solution
The solution I'm looking for can use java or javascript. I have html code in a string, so I can manipulate it before using it with java or subsequently with javascript.
Problem
Anyway, I have to wrap each word with a tag. For instance:
<html> ... > Hello every one, cheers < ... </html>
should be changed to
<html> ... > <word>Hello</word> <word>every</word> <word>one</word>, <word>cheers</word> < ... </html>
Why?
This will help me use javascript to select / highlight the word. It seems the only way to do this is to use the highlightElementAtPoint function, which I added in the JAVASCRIPT tooltip: it just finds an element of a specific x, y coordinate and selects it. I realized that if every word is an element, it will be doable.
The idea is to use this approach so that we can detect the selected text in the Android web interface, even if it would mean using the twisted highlight method. Think a little more and you will find many other applications for this.
JAVASCRIPT Tip
I use the following code to highlight a word; however, this will highlight all the text belonging to a particular tag. When every word is a tag, this will work to some extent. If there is a replacement that will allow me to highlight a word in a certain position, this will also be a solution.
function highlightElementAtPoint(xOrdinate, yOrdinate) { var theElement = document.elementFromPoint(xOrdinate, yOrdinate); selectedElement = theElement; theElement.style.backgroundColor = "yellow"; var theName = theElement.nodeName; var theArray = document.getElementsByTagName(theName); var theIndex = -1; for (i = 0; i < theArray.length; i++) { if (theArray[i] == theElement) { theIndex = i; } } window.androidselection.selected(theElement.innerHTML); return theName + " " + theIndex; }
source share