title: How to highlight text permanently on android webview?
body: <p>I am doing Epub reader and showing book inside android webview.</p>
  
  <p>At present i can highlight text using below javascript </p>
  
  <pre><code>public static String Highlightscript = " &lt;script language=\"javascript\"&gt;" +
  
          "function highlightSelection(){" +
          "var userSelection = window.getSelection();" + 
          "for(var i = 0; i &lt; userSelection.rangeCount; i++)"
          + "  highlightRange(userSelection.getRangeAt(i));" +
           "}" +
          "function highlightRange(range){"+
          "span = document.createElement(\"span\");"+
          "span.appendChild(range.extractContents());"+
          "span.setAttribute(\"style\",\"display:block;background:#ffc570;\");"+
          "range.insertNode(span);}"+
          "&lt;/script&gt; ";
  </code></pre>
  
  <p>and to when user clicks on highlight i do</p>
  
  <pre><code>webView.loadUrl("javascript:highlightSelection()");
  </code></pre>
  
  <p>This highlight the text and i also save the highlighted text in local database</p>
  
  <p>but when user reopens the book i want to show the previous highlighted text . How can i achieve this ?  </p>
  
  <p>i am trying to find the text when user enters the page(which highlights text by default) by</p>
  
  <pre><code>webView.findAllAsync(highlightedText);
  </code></pre>
  
  <p>but if highlighted text was too small like  word "The" , a lot of words will be highlighted . </p>
  
  <p>I already searched on SO , but all questions were unanswered  <a href="https://stackoverflow.com/questions/9872574/can-we-have-area-selection-feature-on-webview-in-android">Question 1</a> and <a href="https://stackoverflow.com/questions/8969448/how-to-highlight-text-permanently-in-webview-in-android">Question 2</a></p>
  
  <p>So is there any other way to achieve this?</p>