Skip to content

Instantly share code, notes, and snippets.

@pcevikogullari
Created January 13, 2017 21:30
Show Gist options
  • Save pcevikogullari/d86b9bef81192701df830e610568a6a2 to your computer and use it in GitHub Desktop.
Save pcevikogullari/d86b9bef81192701df830e610568a6a2 to your computer and use it in GitHub Desktop.
Execute Javascript in webview
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://xxx.xxx.xxx.xxx:yyyy/form");
webview.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
String script = "document.getElementsByName(\"fullname\")[0].setAttribute(\"value\", \"pamir cevikogullari\" ) ";
webview.evaluateJavascript(script, new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
Log.d("LogName", s);
}
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment