Android WebView Javascript getSelection

前端 未结 3 1745
后悔当初
后悔当初 2020-12-05 05:07

I am having some trouble getting the selection from a WebView in Android.

I can get the WebView to go into selection mode. I can even get it to copy the text to the

3条回答
  •  無奈伤痛
    2020-12-05 05:15

    Finally, in Android 4.4 KitKat, the WebView is now based on Chromium.

    Therefore we have access to window.getSelection()!!

    wv.evaluateJavascript("console.log(window.getSelection().baseNode.nodeValue);", null);
    

    Tested on Nexus 5 & Nexus 7.

提交回复
热议问题