问题
I am developing an application where in 1 part I want to add javascript into WebView.. But am not getting how to do it in an appropriate way.. Can anyone pls guide me into this?????
I am doing it like:
wb=(WebView)findViewById(R.id.webView1);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setPluginState(WebSettings.PluginState.ON);
wb.getSettings().setPluginsEnabled(true);
wb.loadUrl("javascript:<script " ></script> ");
wb.setWebViewClient(new HelloWebViewClient());
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
回答1:
It was very simple..also without using any javascriptInterface..In my code, Instead writing:
wb.loadUrl("javascript:<script> </script>");
use,
wb.loadDataWithBaseURL(null,"<script> </script>","text/html","utf-8",null);
and its working now :)
回答2:
Look at these nice tutorials about how to implements javascript in webview in android..
I think its provides you all the information what you needed..
Android WebView
Android WebView, Javascript and CSS
EDIT: Further if your implemented code having any exception or not working then please post that code and exception then here we can help you..
来源:https://stackoverflow.com/questions/8533187/add-javascript-into-webview