问题
Has anyone found a solution for highlighting user-selected blocks of text in a UIWebView?
I have a partial solution in place, however I have been unable to get it to work when the selection includes multiple elements in the DOM. In that case, I can find and highlight the first element in the selection, but javascript seems unable to tell me where the end of the selection is in this case.
It may be that I just don't understand the selection objects completely. It's difficult to find good documentation on them.
回答1:
You can use document.execCommand("HiliteColor")
. I answered a similar question recently:
Making Selection & Adding tag dynamically in JavaScript
Regarding documentation, MDN is pretty good for Selection and Range, although it doesn't really go into detailed examples.
回答2:
I found perfect solution for this issue.Follow This Link.
Good Luck
来源:https://stackoverflow.com/questions/7760268/uiwebview-text-highlighting-solution