0

Hi guys in my web app i wanted to print selected text(say here content in paragraph tag). How to do it in Android WebView, how to select text using JavaScript??

Thanks in advance..

Here is my JavaScript code

<script type="text/JavaScript">

function SelectText()
{
    var txt = '';
     if (window.getSelection)

    {
        txt = window.getSelection();
             }
    else if (document.getSelection)
    {
        txt = document.getSelection();
            }
    else if (document.selection)
    {
        txt = document.selection.createRange().text;
            }
    else return;
document.getElementById("demo").innerHTML=  txt;
}

</script></head>


 <body>
   <p>Hi man how are you?? Hope your doing good..</p>
   <p> id="demo"></p>

  <button> onclick="SelectText()">Selected text</button>

</body>
</html>
  • Please go through the SO post http://stackoverflow.com/questions/4892111/android-webview-javascript-getselection – karthick Feb 20 '13 at 05:46

1 Answers1

1

You wrote

<p> id="demo"></p>

It should be

<p id="demo"></p>

Does this fix the issue or it was misspelling?

Hisham Bakr
  • 559
  • 4
  • 13