Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wesleyduff/403fc3a24f5a0f4508ef0e5f55a95ae9 to your computer and use it in GitHub Desktop.
Save wesleyduff/403fc3a24f5a0f4508ef0e5f55a95ae9 to your computer and use it in GitHub Desktop.
//Java
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("<your html file>"); //not in scope of this gist
webview.setWebViewClient(new WebViewClient(){
public void onPageFinished(WebView view, String url){
//Here you want to use .loadUrl again
//on the webview object and pass in
//"javascript:<your javaScript function"
webview.loadUrl("javascript:myJavaScriptFunc('" + argumentPassingIn + "')"); //if passing in an object. Mapping may need to take place
}
});
//HTML
<!DOCTYPE html>
<html>
<head><title>Demo</title></head>
<body>
<h1>Body</h1>
<script>
myJavaScriptFunc(val){
//Do something with val
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment