2

I have this webview:

<textarea name="text" id="textPage" class="text_area"></textarea>
<script language="javascript" charset="utf-8">
//call some method of javascript.
</script>

Is it possible to set text to textarea and get text from textarea. Set/get data from id(if any method possible) will be appreciated.

Suraj Neupane
  • 489
  • 3
  • 21
  • 1
    You probably need to set up a JavaScript interface. This answer might help. http://stackoverflow.com/questions/8961418/android-simple-user-input-form-web-view-to-back-end-java-with-jquery-mobile – Jimbali Aug 18 '14 at 16:52
  • To get data from a WebView in Android : https://stackoverflow.com/a/76415649/12272687 – Mori Jun 06 '23 at 14:19

1 Answers1

0

After many research i found solution, it might useful in future:

Set Data:

Android:

webView.loadUrl("javascript:setData()");

JS:

function setData(){
//js code
}

Get Data:

Android:

JavascriptInterface jsInterface = new JavascriptInterface(MainActivity.this);
converterWeb.addJavascriptInterface(jsInterface, "Android");//android is a tag.

class:

public class JavascriptInterface {
        Context mContext;

        JavascriptInterface(Context c) {
            mContext = c;
        }

        public boolean getData(String name) {
            Toast.makeText(mContext, "Text: "+name, Toast.LENGTH_SHORT).show();
            return true;
        }
    }

JS:

Android.convertedText(value);//send data in tag.

better option still welcome.

Suraj Neupane
  • 489
  • 3
  • 21