Created
January 13, 2017 21:30
-
-
Save pcevikogullari/d86b9bef81192701df830e610568a6a2 to your computer and use it in GitHub Desktop.
Execute Javascript in webview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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